Rana Rajpoot Rana Rajpoot - 1 year ago 49
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


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


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 Source

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)