A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Databases
»
JDBC
Author
I face a New java.sql.SQLException
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
I like...
posted
Jun 19, 2008 06:55:00
0
When i use the below code it shows an weird error that i was not know before.
And here is my code....
String SQL="INSERT INTO tbl_rmadetails(date,rma_no,customer_id,item_id,customer_inv_no,customer_inv_date,customer_inv_amount,serial_no,fault_desc,replaced_serial_no,status,vendor_id,vendor_inv_no,vendor_invoice_date,vendor_rma_ref,remarks)"; ps = con.prepareStatement(SQL); ps.setDate(1,da); ps.setInt(2,rm1); ps.setString(3,customer); ps.setString(4,item); ps.setInt(5,in1); ps.setDate(6,date1); ps.setNull(7,11); ps.setNull(8,11); ps.setString(9,fdesc); ps.setNull(10,11); ps.setString(11,status); ps.setString(12,vend); ps.setNull(13,11); ps.setNull(14,11); ps.setNull(15,21); ps.setNull(16,21); f = ps.executeUpdate();
And err here is the error
-------------------------
java.sql.SQLException: Parameter index out of range (1>0) at com.rajk.javacode.servlets.RMAEntryModel(RMAEntryModel.java:201) at com.rajk.javacode.servlets.RMAEntryServlet(RMAEntryServlet.java:49)
where the 201st line of RMAEntryModel is ps.setDate(1,da);
what should i do with...
Any help would be appreciated
Never try to be a hard-worker. Be a smart-worker.
My Blog
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
I like...
posted
Jun 19, 2008 07:12:00
0
Parameter index out of range (1>0)
You are using a
PreparedStatement
but have not set any bind parameters. All your set methods have no where to bind their values.
To use PreparedStatements, you need to supply placeholders for the various set methods you call to bind their values. FOr example:
String sql = "insert into foo (id, name) values (?,?) ;" PreparedStatement ps = connection.prepareStatement(sql); ps.setInt(1, 1); // binds a value to the first '?' ps.setString(2,"bar"); // binds a value to the second '?'
[ June 19, 2008: Message edited by: Paul Sturrock ]
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
I like...
posted
Jun 19, 2008 22:42:00
0
Thanks Paul Sturrock,
Now i cleared the error.Thanks for your help. Now i inserted the null values in my table. I have to move onto the next step of the project.
David O'Meara
Rancher
Joined: Mar 06, 2001
Posts: 13459
I like...
posted
Jun 19, 2008 22:45:00
0
beerchug to you too
subject: I face a New java.sql.SQLException
Similar Threads
Getting strange exception while executing preparedStatement.
save Date() into mysql Timestamp
Inserting date into an MS Access DB
What problem with this batch update ?
EJB Confusion (help the newbie)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter