SQL Syntax Error Exception in jdbc
SQL Syntax Error Exception in jdbc
Here is my code import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.Scanner; public class JdbcEx2 static final String usernameroot; static final String passwordMyAditya16; static final String drivercom.mysql.cj.jdbc.Driver; static final String urljdbc:mysql:localhost; public static void mainString args Scanner scnew ScannerSystem.in; String sql,name; int id,marks; Statement stnull; Connection cnnull; char ch; try Class.forNamedriver; cnDriverManager.getConnectionurluseSSLfalse,username,password; stcn.createStatement; sqlcreate database student;; sqldrop database student;; int rowsst.executeUpdatesql; System.out.printlnDatabase created; sql CREATE TABLE student id INTEGER not NULL, name VARCHAR255, marks INTEGER, PRIMARY KEY id ;; rowsst.executeUpdateuse student;sql; System.out.printlnstudent table created; System.out.printlnDo you want to insert some rows; chsc.next.charAt0; while chy System.out.printlnEnter some data; sqlinsert into student VALUES,,; stcn.prepareStatementsql; System.out.printnEnter id:; idsc.nextInt; System.out.printnEnter name:; namesc.next; System.out.printnEnter marks:; markssc.nextInt; PreparedStatement st.setInt1,id; PreparedStatement st.setString2,name; PreparedStatement st.setInt3,marks; cn.close; st.close; sc.close; catch SQLException e e.printStackTrace; catchException e e.printStackTrace; finally try ifstnull st.close; catchSQLException e2 e2.printStackTrace; try ifcnnull cn.close; catchSQLException e1 e1.printStackTrace; it says:java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near CREATE TABLE student id INTEGER not NULL, name VARCHAR255, marks INTEGER, PRI at line 1 what is issue with this snippet sql CREATE TABLE student id INTEGER not NULL, name VARCHAR255, marks INTEGER, PRIMARY KEY id ;;
Комментарии
Отправить комментарий