Tuesday 15 July 2014

java - JDBC insert error -



java - JDBC insert error -

i trying insert info database jdbc. using right table, db name, , parameters. checked.

code

public static void main(string[] args) throws ioexception/*, classnotfoundexception, sqlexception*/ { datainputstream d = new datainputstream(system.in); system.out.println("enter employee id : "); @suppresswarnings("deprecation") int empid = integer.parseint(d.readline()); system.out.println("enter employee name : "); @suppresswarnings("deprecation") string empname = d.readline(); system.out.println("enter employee id : "); @suppresswarnings("deprecation") double empsalary = double.parsedouble(d.readline()); seek { class.forname("com.mysql.jdbc.driver"); } grab (classnotfoundexception e) { e.printstacktrace(); } connection con; seek { con = drivermanager.getconnection("jdbc:mysql://localhost:3306/testdb","root",""); preparedstatement pst = con.preparestatement("insert `employee` values(?,?,?"); pst.setint(1, empid); pst.setstring(2, empname); pst.setdouble(3, empsalary); int rowcount = pst.executeupdate(); system.out.println(rowcount + " row has been instered"); } grab (sqlexception e) { e.printstacktrace(); }

and here errors gives me when seek run it:

com.mysql.jdbc.exceptions.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax utilize near '' @ line 1 @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:936) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:2985) @ com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:1631) @ com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:1723) @ com.mysql.jdbc.connection.execsql(connection.java:3283) @ com.mysql.jdbc.preparedstatement.executeinternal(preparedstatement.java:1332) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:1604) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:1519) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:1504) @ com.test.jdbcexample.main(jdbcexample.java:47)

you have syntax error in line:

preparedstatement pst = con.preparestatement("insert `employee` values(?,?,?");

you missing closing parenthesis values clause.

java mysql sql jdbc insert

No comments:

Post a Comment