Rana Rajpoot Rana Rajpoot - 4 months ago 10
Java Question

How can I insert data in mysql using JDBC? What's wrong in my JDBC code

How can I execute this statement using JDBC? What is the error in it how can I remove this error from this

rs=st.executeQuery(Sql);


[enter image description here][1]//This error coming.

statement2.jsp

String Sql="insert into teacher2(firstname,lastname,username,password,confirmpassword,email,month,day,year,gender) values('"+name+"','"+abc+"','"+cde+"','"+pass+"','"+confpass+"','"+emails+"','"+months+"','"+day+"','"+year+"','"+gender+"')";

rs=st.executeQuery(Sql); //`Why this statement is not executed`

Answer

As the error message says, st.executeQuery(Sql) is only for queries which reads data. For Data manipulation (insert/update/delete), you have to use st.executeUpdate(Sql)