连接数据库建表中出现如下报错,学生刚入门,求大神帮忙看一下原因
Exception in thread "main" java.lang.NullPointerException
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1214)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1205)
at Week4.One.main(One.java:29)
代码如下
package Week4;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class One {
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1:3306/hello";
Connection conn = DriverManager.getConnection(url, "root", "");
Statement stat = conn.createStatement();
stat.close();
conn.close();
stat.executeUpdate("create table oe_class("
+ "clid int not null,"
+ "coid int not null,"
+ "seeid int not null,"
+ "uname int not null,"
+ "sesid int not null,"
+"clweek int not null,"
+"primary key (clid);"
+ ")");
stat.executeUpdate("create table oe_course("
+ "coid int not null,"
+ "coname varchar(20) not null,"
+"primary key (coid);"
+ ")");