qq_40230610 2018-04-02 11:05 采纳率: 40%
浏览 947
已采纳

java 连接数据库出现问题

连接数据库建表中出现如下报错,学生刚入门,求大神帮忙看一下原因
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);"
                + ")");

  • 写回答

7条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 VBA跨工作簿获取目标工作簿内已有数据的列号
      • ¥30 Dijkstra‘s 最短路径
      • ¥15 在线教育培训平台,主要以点播视频和在线练习测试为主,除将视频做切片外,有其他哪种方式降低流量?(关键词-带宽速率)
      • ¥20 用c语音或c++实现银行叫号系统
      • ¥15 人工智能 规则正向演绎和推理
      • ¥20 基于STM32F401的电子密码锁设计
      • ¥15 famamacbeth回归中遇到only size-1 arrays can be converted to Python scalars,求解答
      • ¥15 单片机多个自锁按键的编程实践
      • ¥15 用python操作redis存储中文后,再取出的数据变成了乱码怎么办?
      • ¥15 C语言简单排序问题有偿求解