Why is this java code not saving data in database?

391 views Asked by At
try{
     Class.forName("com.mysql.jdbc.Driver").newInstance();

     try{
            try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/crm","root","")) {
                PreparedStatement pstmt=con.prepareStatement("INSERT INTO user_tbl (email, password, role) VALUES (?,?,?) ");

                pstmt.setString(1,"[email protected]");
                pstmt.setString(2,"[email protected]");
                pstmt.setString(3,"Engineer");

                int z=pstmt.executeUpdate();

                }
            } catch(SQLException exception1) {
                System.out.println("Caught an exception "+exception1);
            }
      } catch(ClassNotFoundException | IllegalAccessException | InstantiationException e) {
          System.out.println("No driver found "+e);
    }

Everything is ok in database. i.e. there is database as well as table with same columns. But, this code is not working. What may be the problem?

0

There are 0 answers