my dog learned polymorphism*
The moose likes JDBC and the fly likes Prepared statement help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Prepared statement help" Watch "Prepared statement help" New topic
Author

Prepared statement help

Bob Rocks
Greenhorn

Joined: Oct 21, 2004
Posts: 23
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

Joined: Aug 13, 2004
Posts: 1081

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);


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Bob Rocks
Greenhorn

Joined: Oct 21, 2004
Posts: 23
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

Joined: Jan 10, 2002
Posts: 61426
    
  67

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


What's with the parens in the driver name?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

add the classes12.zip in your classpath
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by Bear Bibeault:


What's with the parens in the driver name?


Thanks Bartender,

I missed to see parens
Bob Rocks
Greenhorn

Joined: Oct 21, 2004
Posts: 23
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

Joined: Jan 10, 2002
Posts: 61426
    
  67

Take out the parens, not the quotes!

Bob Rocks
Greenhorn

Joined: Oct 21, 2004
Posts: 23
wow, paying attention to what I am doing would really help in this situation!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

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

Joined: Oct 21, 2004
Posts: 23
Oh yeah, it all kind of fell into place, thanks a ton for your help guys!
 
wood burning stoves
 
subject: Prepared statement help