-1

I am doing a simple program in netbeans. Following is the Exception caused

java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

</head>
<body>
    <form method="post" action="home/signup">
    Enter id:<input type="text" name="userid">
    Enter password<input type="password" name="pwd1">
    <br>
    <input type="submit" value="Create">

    </form>
</body>

Servlet:

   {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/login", "root","12345678");
            Statement stmt=conn.createStatement();

            int n=stmt.executeUpdate("INSERT INTO `login`.`tables` (`"+request.getParameter("userid")+"`) VALUES ('"+request.getParameter("pwd1")+"');");

            out.println("Rows updated: "+n);



        }catch(Exception ee){out.println(ee.toString());}
    }
}

I tried doing everything and could not find a solution. Thanks in advance for helping.

5
  • What is the stack trace? Commented Jun 24, 2018 at 15:34
  • SqlInjection alert Commented Jun 24, 2018 at 15:35
  • Possible duplicate of java.math.BigInteger cannot be cast to java.lang.Integer Commented Jun 24, 2018 at 15:37
  • @NicolásAlarcónR. no that Question code has interger values conversion. Commented Jun 24, 2018 at 16:11
  • Please post the full exception stacktrace. Als be aware that your insert query is 1) incorrect as you try to put a value in the column list and 2) very unsafe because it is extremely vulnerable to SQL injection as you are using direct user input in a query without using a prepared statement. Commented Jun 25, 2018 at 7:20

1 Answer 1

1

Judging by the syntax, the query that you wrote is wrong. You can check the insert statement format here. So basically what you should write is something in the line of:

insert into login.tables (user_id, password) values("some_user", "s3cr3t")

instead, it seems that you are not listing the column names first, then assigning the values, but putting the username value in the column names space and the password in the values part.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried using this syntax,Still the Exception Exists.😅
Can you update the question with the modification that you applied?
Thanks for the help. I just updated my jdbc connector/j drivers, I was using old version of drivers. Issue solved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.