• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC-MS Access and string class

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic