Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC-MS Access and string class

 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Want to use a update statement as follows:

String updateString="Update from table1 set coloum1= "+
" ,coloum1= "+"\""+"Mr"+"\""+
" ,coloum2= "+"\""+"Dressup "+"\""+
" ,coloum3="+"\""+"TickleTrunk"+"\""+
"where primaryKey=list.get(count)";

Basically the problem is the "" inside a string. with the \" it seems to compile but I get SQL Exceptions because of the 'updateString'. What is the proper way to do this? I also know you can cycle the resultSet and use it as a parameter that way but i dont want to cause my strings are built from reading files not from already processed resultSets.

thanks
roba
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Rob,

use a PreparedStatement, it will take care of the quotes for you.
See for an example:
http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html

Herman
 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you dont want to use PreparedStatement you can use single quote it will more simpler.

also there is problem in code you have taken coloum1= twice.

Check it again.



Thanking You
- Kuldeep Yadav
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kuldeep Yadav:
If you dont want to use PreparedStatement you can use single quote it will more simpler.

That is really a bad idea.

Use PreparedStatement all the way.
 
han smile
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic