• 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

Prepared statement help

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I am having some trouble with prepared statements. I am getting an error when I try to run this code:



I get an incompatible error, cannot convert string to int.

I have just started to work with prepared statements and I am sure it is something dumb! Also, I am trying to write an interface which will allow a user to enter data into fields, then I want to pass it to the db. Normally I would do this over a couple pages, is there a better way?

Some of the fields will contain single quotes and have been a problem, which is why I am trying to figure out this prepared statement stuff anyway! So if someone could give me a quick code example of how to pull this off like this I would appreciate it greatly!

thanks guys!
-Bob
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
better you refer javadoc for preparedStatment

your problem can be solved as by setting your statemenmt in following manner

pstmt.setString(1,vtxt1);
pstmt.setString(2,vtxt2);
 
Bob Rocks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, that did help, but now I am getting this error

java.lang.ClassNotFoundException: oracle/jdbc/driver/OracleDriver()
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Class.forName("oracle.jdbc.driver.OracleDriver()");



What's with the parens in the driver name?
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add the classes12.zip in your classpath
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


What's with the parens in the driver name?



Thanks Bartender,

I missed to see parens
 
Bob Rocks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I thought the parens were odd too, but they were in some crappy book I started using. I have since stopped using that book!

I took out the parens and now it gives me another error:

Undefined variable, class, or package name: oracle
Class.forName(oracle.jdbc.driver.OracleDriver());

and classes12 is in the classpath...
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take out the parens, not the quotes!

 
Bob Rocks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow, paying attention to what I am doing would really help in this situation!
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you did this pre-coffee, it's understandable. I've learned never to code before coffee!

Seriously, do you understand why and how this works now?
 
Bob Rocks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yeah, it all kind of fell into place, thanks a ton for your help guys!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic