Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
JDBC and Relational Databases
prepareStatement() returns 0 value
Tijo Mathew
Greenhorn
Posts: 16
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I am using the following code in
struts
. When i call this method from an action class, it prints null value. It not inserting values in to database. Any help is appreciable.
public String authenticateUser(String buttonAction, String [] valuesOfFields) { int n=0; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/usermaintenancedb", "root", "root"); } catch(Exception dbConnect) { System.out.println("error in Db connection method getDbConnection()"+dbConnect.getCause()); } int len=valuesOfFields.length; String query="INSERT INTO userinfotbl (username,password,firstname,middlename,lastname,gender,dateofbirth, emailid,mobileno,landno,address,city,state,pincode) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; try { pstmt=con.prepareStatement(query); int j=0; for(int i=0;i<len;i++) { ++j; pstmt.setString(j,valuesOfFields[i]); } n=pstmt.executeUpdate(); } catch(Exception db) { System.out.println("error in prepared statement authenticateUser()"+db.getCause()+n); return "failure"; } return "success"; }
Thanks in advance
Rob Spoor
Sheriff
Posts: 22815
132
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Just call
db.printStackTrace()
. It will show you the error itself, and its cause if it has one.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Tijo Mathew
Greenhorn
Posts: 16
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks...i rectified the error....
Rob Spoor
Sheriff
Posts: 22815
132
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Would you mind telling us what the error was? That way somebody else may learn from it in the future.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Tijo Mathew
Greenhorn
Posts: 16
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
actually it was date mismatching with MYSQL date data type. I got through using the db.printStackTrace() in my code. Thanks for help.
Rob Spoor
Sheriff
Posts: 22815
132
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You're welcome
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
this code is giving file not found exception
urgent help needed in JTable !!!!!!!!!!!!!!
Working with registry
Getting the arraylist through session
Finding Nth Largest element of an array without sorting
More...