jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes Need a small change in code and fix the error. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Need a small change in code and fix the error." Watch "Need a small change in code and fix the error." New topic
Author

Need a small change in code and fix the error.

Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Hi,
i am writing a code to enter datas from a jsp where in the table created consists of 3 cols Query_ID, Query_Raised and TR. here Query_ID is to be assigned automatically, Query_Raised is to be taken from another page where the field name is txt2, and TR is the system time. please help me with the below code. And also i am receiving an error as java.sql.SQLException: Invalid column index .
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Hello and welcome to the ranch.
I added code tags to your post doesn't it look prettier and easier to read. it made it a 2 second job to spot the bug in your code.

The index for the ps.set... methods starts at 1 (not zero like everything else), it isn't refering to the column in your SQL but to which '?' it refers to, the 1st one the 2nd one etc.

And for future reference you really should get used to using a servlet for your database code. pleae read this very helpful page: why not use scriptlets
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1621
    
  13

1. Read the error message. It talks about an invalid column index in your SQL call so you know where to start looking.
2. So look at your SQL and count the parameters you want to pass in.
3. Look at the lines where you set these parameters and see if you can figure out where the problem is.

By the way, you shouldn't data access code in your JSPs anyway.


No more Blub for me, thank you, Vicar.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Hi Chris and Wendy,
Thanks for your answers. my previous error was solved, but the problem i'm getting is that i'm able to see both time and date but i want only time and it should be system time. here i'm unable to get system time it is showing 12:00:00:00 AM. And thanks for suggesting me to use servlets instead of JSPs and could you also suggest me some good sites to learn servlets as i'm totally new to J2EE.

Thanks,
Rakesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need a small change in code and fix the error.
 
Similar Threads
Servlet becomming slow
Servlet becomming slow
Connection Pooling
send variable value from one servlet to another servlet for itext pdf
Problem in using date in WHERE clause in SELECT query in Servlet.