File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes JDBC-MS Access and string class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC-MS Access and string class" Watch "JDBC-MS Access and string class" New topic

JDBC-MS Access and string class

rob armstrong
Ranch Hand

Joined: Jul 25, 2005
Posts: 77
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.

Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Rob,

use a PreparedStatement, it will take care of the quotes for you.
See for an example:

Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Dec 24, 2008
Posts: 2

Love java, love life
Don't get me started about those stupid light bulbs.
subject: JDBC-MS Access and string class
It's not a secret anymore!