wood burning stoves 2.0*
The moose likes JDBC and the fly likes Inserting values from textbox into database 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 "Inserting values from textbox into database" Watch "Inserting values from textbox into database" New topic
Author

Inserting values from textbox into database

Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
I am trying to insert the values from the textfields into the database.this is the code.

The below file is chacha.jsp


I get this error when i execute the program.
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when converting the varchar value 'null' to data type int.
root cause

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when converting the varchar value 'null' to data type int.
note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.


--------------------------------------------------------------------------------

Sun Java System Application Server 9.1

In my sus db there are 3 coloumns, Sujay whose datatype is varchar, Kshitij datatype is varchar and Pariniti is number)
Please help me out with this!!
-regards sujay
Leander Kirstein-Heine
Greenhorn

Joined: Mar 13, 2009
Posts: 4
The last value in your insert statement should not be quoted - because it's a number. Your line 14 must look like this:



It will be much easier to use prepared statements. More about that you can read here: http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Sujay Nadkarni wrote:

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when converting the varchar value 'null' to data type int.

Check out which column has type "int", and then pass the appropriate column default value like, 0 for null

HTH


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
hey thanks alot..it worked for me!! thanks alottttt
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Save you from all that trouble and SQL injection risks: use PreparedStatement.
Also writing Java code in Java classes instead of JSP files will save you from future trouble.
 
Consider Paul's rocket mass heater.
 
subject: Inserting values from textbox into database