Mysql jdbc中的SQL语法错误异常

Mysql jdbc中的SQL语法错误异常,mysql,Mysql,这是我的密码 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 username="root"; stati

这是我的密码

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 username="root";
static final String password="MyAditya16*";
static final String driver="com.mysql.cj.jdbc.Driver";
static final String url="jdbc:mysql://localhost/";
public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String sql,name;
    int id,marks;
    Statement st=null;
    Connection cn=null;
    char ch;
    try {
        Class.forName(driver);
        cn=DriverManager.getConnection(url+"?useSSL=false",username,password);
        st=cn.createStatement();
        //sql="create database student;";
        sql="drop database student;";
        int rows=st.executeUpdate(sql);
        System.out.println("Database created");
        sql ="CREATE TABLE student (id INTEGER not NULL, name VARCHAR(255), marks INTEGER, PRIMARY KEY ( id ));";
        rows=st.executeUpdate("use student;"+sql);
        System.out.println("student table created");
        System.out.println("Do you want to insert some rows?");
        ch=sc.next().charAt(0);
        while (ch=='y'){
            System.out.println("Enter some data");
            sql="insert into student VALUES(?,?,?)";
            st=cn.prepareStatement(sql);
            System.out.print("\nEnter id:");
            id=sc.nextInt();
            System.out.print("\nEnter name:");
            name=sc.next();
            System.out.print("\nEnter marks:");
            marks=sc.nextInt();
            ((PreparedStatement) st).setInt(1,id);
            ((PreparedStatement) st).setString(2,name);
            ((PreparedStatement) st).setInt(3,marks);
        }
        cn.close();
        st.close();
        sc.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } catch(Exception e){
        e.printStackTrace();
    }
    finally{
        try{
            if(st!=null){
                st.close();
            }
        }
        catch(SQLException e2){
            e2.printStackTrace();
        }try{
            if(cn!=null){
                cn.close();
            }
        }
        catch(SQLException e1){
            e1.printStackTrace();
        }
    }
}

}
它说:java.sql.SQLSyntaxErrorException:您的sql语法有错误;检查与MySQL服务器版本对应的手册,以了解在第1行的“CREATE TABLE student(id INTEGER not NULL,name VARCHAR(255),marks INTEGER,PRI)”附近使用的正确语法

这段代码有什么问题

sql ="CREATE TABLE student (id INTEGER not NULL, name VARCHAR(255), marks INTEGER, PRIMARY KEY ( id ));";

你的myql服务器版本是什么?一旦你的数据库被删除,我不确定你是如何创建表的。这就是问题所在??sql=“drop database student;”;是吗?@user641887我的sqlserver版本是8.0.11。Drop table不是问题…如果我创建它,它将有相同的错误。@user641887请检查我提到的create table代码段。您确定executeupdate在一次调用中支持多个语句吗?