Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PreparedStatement/Parameter Error

Status
Not open for further replies.

Draug

Programmer
Apr 18, 2001
77
0
0
CA
Greetings,
The code below creates a runtime Null Pointer Exception.

Can anyone tell me why? If I replace the ':well' and ':attach' with '?', everything works fine, but I dont think I should have to do that.

////////////////////////////////////////////////////////////
queryString = "Select Path From LW_ATTACHMENT Where Well_Id=:well and Attachment_Id=:attach";

ps = conn.prepareStatement(queryString);
ps.setString(1, "1");
ps.setString(2, "27038");
rset = ps.executeQuery();
////////////////////////////////////////////////////////////

Thanks alot people :)
 
you do know that the "?" is required... that's the syntax... check out the doc on java.sql package

the method is implemented to look for '?' char, how can you just change the pre-condition of the method.
 
Well, someone told me that it was not required, and that naming a parameter with a colon followed by a name would work...guess it wont.

Thanks
 
maybe it would, but from what i have seen and used to date, prepared statements are pretty iffy... it works if it is used perfectly... otherwise it dies pretty badly... it maybe easier to use resource bundler and get your sql pieces and build up the sql str yourself. a better practice yet is to use store procs.

good luck,

dix
 
Using the java.sql.* package, you have to create prepared statements with the '?' character

From SQL*Plus (Oracle), you create bind variables by using the :variable notation.

 
I use java.sql and have no problem using ':id' instead of '?'. Are we using different releases or something?

Regardless, you should do what works for you.
 
Daniel135,

What release are you using? I am using JDK 1.3, which packaged with JBuilder4.

For a variety of longwinded reasons, it would be much better if I could use ':id' instead of '?'.

Draug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top