Results 1 to 2 of 2
- 01-31-2012, 02:19 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 1
- Rep Power
- 0
Plz help for some reason this code is not compiling
I am trying to parse an Integer to put it into a NUMERIC value into a database form a webpage using a servlet in Netbeans. The problem is that when I am parsing it I keep getting the error cannot put a CHAR into a NUMERIC value can someone please tell me what I am doing wrong here is my code.
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
String ID = request.getParameter("ID");
int IDNum = Integer.parseInt(ID);
try
{
stmt = connection.createStatement();
int update_count = stmt.executeUpdate("INSERT INTO APP.CUSTOMERINFO (CUSTOMERID,CUSTOMERNAME,SHIPPINGADDRESS) " +" VALUES("+ IDNum + ", '" + Name + "', '" + Address + "')");
stmt.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
and this is the error.
SEVERE: java.sql.SQLSyntaxErrorException: Columns of type 'NUMERIC' cannot hold values of type 'CHAR'.
Please this is driving me insane.
- 01-31-2012, 09:48 AM #2
Re: Plz help for some reason this code is not compiling
First off, your code is fragile and prone to SQL injection. Use PreparedStatement, not Statement.
That should solve the problem you're facing, too.
And as there's nothing NetBeans-specific about the question, I'm moving it to JDBC.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
Code stops for no reason
By Bagzli in forum New To JavaReplies: 9Last Post: 03-03-2011, 04:56 AM -
simple code not compiling
By cliffh in forum New To JavaReplies: 8Last Post: 09-30-2010, 06:47 AM -
my code compiling but not running
By girishkumar in forum New To JavaReplies: 16Last Post: 03-16-2010, 05:45 PM -
Help me out in compiling the source code
By aks.nitw in forum Advanced JavaReplies: 3Last Post: 10-17-2008, 09:33 AM -
Trouble compiling code
By waelhelbawi in forum New To JavaReplies: 1Last Post: 05-12-2008, 05:25 AM
Bookmarks