sql="select * from movie where ID='"+ searchid +"'";
  try{
ResultSet conn=new jdbcfile().executeQuery(sql);没看到楼主哪里去的数据库连接会话Connection,也没有看到statment,不理解楼主的写法

解决方案 »

  1.   

    ResultSet conn=new jdbcfile().executeQuery(sql);这个new jdbcfile()里面有问题,估计有一项没初始化
      

  2.   

    这是数据库里的
    package com.movie.sql;import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;public class jdbcfile {
    Connection conn;
    Statement stmt;
    int inorupdatevalue=-1;


    //驱动  链接  执行语句  关闭连接
    static String url = "jdbc:mysql://localhost:3306/movie";
    static String username = "root";
    static String password = "qwer";
    public void getConnection(){
    try {
    //加载驱动
    Class.forName("com.mysql.jdbc.Driver");
    //建立连接
    conn = DriverManager.getConnection(url,username,password);

    stmt = conn.createStatement();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    //执行sql语句
    public ResultSet executeSQL(String sql){
     try {
    stmt.executeUpdate(sql);
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return null;
    }

    //定义查询数据的方法
    public synchronized ResultSet executeQuery(String sql)throws
    Exception{
    ResultSet rs=stmt.executeQuery(sql);
    return rs;
    }
    //定义插入的方法
    public synchronized int insert(String sql)throws
    Exception{
    inorupdatevalue=stmt.executeUpdate(sql);
    return inorupdatevalue;
    }
    //定义修改数据的方法
    public synchronized int update(String sql)throws
    Exception{
    inorupdatevalue=stmt.executeUpdate(sql);
    return inorupdatevalue;
    }
    //定义删除的方法
    public synchronized int del(String sql)throws
    Exception{
    inorupdatevalue=stmt.executeUpdate(sql);
    return inorupdatevalue;
    }
    //定义关闭数据库链接的方法
    public void close()throws Exception{
    conn.close();
    }}
      

  3.   


    conn = DriverManager.getConnection(url,username,password);stmt = conn.createStatement();从conn 开始断点,看conn 有没有拿到,看stmt 有没有创建成功