File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC-MS Access and string class" Watch "JDBC-MS Access and string class" New topic
Author

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.

thanks
roba
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:
http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html

Herman
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
Greenhorn

Joined: Dec 24, 2008
Posts: 2


Love java, love life
 
wood burning stoves
 
subject: JDBC-MS Access and string class
 
Similar Threads
Using Variables to UPDATE
updateString() is inserting numbers
Problem with the "where" query.
How prepared statements shall be used
editing records