java - unable to create the profile com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; -
im making simple database ,so here database schema:
create database studentapp_db ; create table students_info ( regno int(10) not null, firstname varchar (50) , middlename varchar (50), lastname varchar (50), primary key(regno) ) ; create table gaurdian_info ( regno int(10) not null, gfirstname varchar (50) , gmiddlename varchar (50), glastname varchar (50), primary key(regno) ) ; create table students_otherinfo ( regno int(10) not null, isadmin varchar (1) , passowrd varchar (50), primary key(regno) ) ;
now, i'm inserting values run configuration that's giving me kind of errors;
unable create profile com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near '10,'aayush','kumar','na')' @ line 1 @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknownsource) @ java.lang.reflect.constructor.newinstance(unknown source) @ com.mysql.jdbc.util.handlenewinstance(util.java:406) @ com.mysql.jdbc.util.getinstance(util.java:381) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1030) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:956) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3515) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3447) @ com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:1951) @ com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:2101) @ com.mysql.jdbc.connectionimpl.execsql(connectionimpl.java:2554) @ com.mysql.jdbc.preparedstatement.executeinternal (preparedstatement.java:1761) @ com.mysql.jdbc.preparedstatement.executeupdate (preparedstatement.java:2046) @ com.mysql.jdbc.preparedstatement.executeupdate (preparedstatement.java:1964) @ com.mysql.jdbc.preparedstatement.executeupdate (preparedstatement.java:1949) @ com.jspider.jdbc.common.transactionplusassignmentexample.main (transactionplusassignmentexample.java:35)
and here code java:
package com.jspider.jdbc.common; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.sqlexception; import com.mysql.jdbc.driver; public class transactionplusassignmentexample { public static void main(string[] args) { java.sql.connection con = null; preparedstatement pstmt1 = null; preparedstatement pstmt2 = null; preparedstatement pstmt3 = null; //1 load db driver try { driver driverref = new driver(); drivermanager.registerdriver(driverref); //2 db connection via driver string dburl = "jdbc:mysql://localhost:3306 /studentapp_db?user=j2ee&password=j2ee"; con = drivermanager.getconnection(dburl); //3. issue sql queries via connection string query1 = "insert students_info" + "values(?,?,?,?)" ; pstmt1 = con.preparestatement(query1); pstmt1.setint(1,integer.parseint(args[0])); pstmt1.setstring(2,args[1]); pstmt1.setstring(3,args[2]); pstmt1.setstring(4,args[3]); int count1 =pstmt1.executeupdate(); string query2 = "insert guardian_info" + "values(?,?,?,?)" ; pstmt2 = con.preparestatement(query2); pstmt2.setint(1,integer.parseint(args[0])); pstmt2.setstring(2,args[4]); pstmt2.setstring(3,args[5]); pstmt2.setstring(4,args[6]); int count2 =pstmt2.executeupdate(); string query3 = "insert students_otherinfo" + "values(?,?,?,)" ; pstmt3 = con.preparestatement(query3); pstmt3.setint(1,integer.parseint(args[0])); pstmt3.setstring(2,args[7]); pstmt3.setstring(3,args[8]); int count3 =pstmt3.executeupdate(); //4 process results system.out.println("profile created sucessfully"); system.out.println("row affected s_i:"+count1); system.out.println("row affected g_i:"+count2); system.out.println("row affected s_oi:"+count3); } catch (sqlexception e) { system.err.println("unable create profile"); e.printstacktrace(); }finally { //close jdbc object //close 3 preparedstatement object try { if (con!= null){ con.close(); } if (pstmt1!= null){ pstmt1.close(); } if(pstmt2!= null){ pstmt2.close(); } if(pstmt3!= null){ pstmt3.close(); } } catch( sqlexception e) { e.printstacktrace(); }//end of outside class try catch } } }
please im new java ;
add space between "students_otherinfo" , "values"
string query3 = "insert students_otherinfo " + "values(?,?,?,)" ;
instead of
string query3 = "insert students_otherinfo" + "values(?,?,?,)" ;
and remove "," :
string query3 = "insert students_otherinfo " + "values(?,?,?)" ;
edit : after comment
and replace guardian gaurdian in scheam. or change schema (better).
Comments
Post a Comment