Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting values from textbox into database

 
Sujay Nadkarni
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sujay Nadkarni
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks alot..it worked for me!! thanks alottttt
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic