Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prepared statement help

 
Bob Rocks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you, that did help, but now I am getting this error

java.lang.ClassNotFoundException: oracle/jdbc/driver/OracleDriver()
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add the classes12.zip in your classpath
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take out the parens, not the quotes!

 
Bob Rocks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, paying attention to what I am doing would really help in this situation!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Oh yeah, it all kind of fell into place, thanks a ton for your help guys!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic