• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

JDBC-MS Access and string class

 
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
 
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
 
Ranch Hand
Posts: 162
Hibernate Spring Java
  • 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
 
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!