装载驱动程序出错了,根据错误信息,应该是驱动程序参数没写完整在java中,连接数据库时,应该采用你采用的数据库提供商所提供的驱动程序

解决方案 »

  1.   

    sqlstr = "select * from employee where employeeName='"+ms+"'";
      

  2.   

    string url = "jdbc:odbc:shop";
    修改为
    String url = "jdbc:odbc:Driver = {Microsoft Access Driver (*.mdb)}; DBQ=C:/CDShop.mdb";
    运行后是同样的错误
      

  3.   

    按zjpangxie(买套房子咋就那么麻烦) 大哥的方法
    显示错误:无效的描述器索引
      

  4.   

    将你的sql语句直接在access下运行看看。
      

  5.   

    如:zjpangxie(买套房子咋就那么麻烦)所言,你的sqlstr的写法不对: 应该写成:"select * from employee where employeeName='"+ms+"'";
      

  6.   

    import java.sql.*;public class Test{
    public static void main(String[] args){
         String ms = "sun";
    String sqlstr = "select * from employee where employeeName = 'ms'";
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url = "jdbc:odbc:shop";
    Connection conn = DriverManager.getConnection(url,"","");
    Statement stmtNew = conn.createStatement();
    ResultSet s= stmtNew.executeQuery(sqlstr);
    s.next();
    System.out.println(s.getString(2));
    }catch(SQLException e1){
    System.out.println(e1.getMessage());
    }catch(Exception e2){
    System.out.println("出错了");
    }    }
    }========================================在我的机器上可以运行,不过你的保证Employee表中有记录
      

  7.   

    sqlstr的写法不对,
     应该写成:
    sqlstr="select * from employee where employeeName='"+ms+"'";
      

  8.   

    sqlstr="select * from employee where employeeName='"+ms+"'";
    ms是变量应该"+ms+"这样引用
      

  9.   

    String ms = "sun";
    sqlstr = "select * from employee where employeeName = ms";
    ----->干嘛不直接这样呢
    String sqlstr = "select * from employee where employeeName = sun";或者你用PreparedStatement吧。灵活性更大一些
      

  10.   

    string url = "jdbc:odbc:shop";
    'string'这样定义可以吗?
      

  11.   

    resultset s= stmtNew.executeQuery(sqlstr);    ResultSet s =
      

  12.   

    conn.createStatement();
    里边应该有参数!
    conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
      

  13.   

    conn.createStatement();
    里边应该有参数!
    conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);而且,SQL应该是
    sqlstr = "select * from employee where employeeName='"+ms+"'";
      

  14.   

    conn.createStatement();
    里边应该有参数!
    conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);而且,SQL应该是
    sqlstr = "select * from employee where employeeName='"+ms+"'";
      

  15.   

    sqlstr = "select * from employee where employeeName = ms";
    写错了,应该为
    sqlstr = "select * from employee where employeeName ='" + ms + "'";
      

  16.   

    变量连接有问题,要加 +变量+sqlstr = "select * from employee where employeeName = ms";
    写错了,应该为
    sqlstr = "select * from employee where employeeName ='" + ms + "'";
      

  17.   

    “我个人喜欢用PreparedStatement ”
    String ms = "sun";
    sqlstr = "select * from employee where employeeName = ?";
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      string url = "jdbc:odbc:shop";
      Connection conn = DriverManager.getConnection(url, "", "");
      PreparedStatement stmtNew = conn.prepareStatement(sqlstr);
      stmtNew.setString(1, ms);
      ResultSet rs = stmtNew.executeQuery();
      /*
       * 做你想做的操作
       */
      if(rs!=null)  //最重要别忘记关闭哦,不然执行多了就会有错误。
       rs.close();
      if(stmtNew!=null)
      stmtNew.close();
    } catch (SQLException e1) {
      System.out.println(e1.getMessage());
    } catch (Exception e2) {
      System.out.println("出错了");
    }
      

  18.   

    String sqlstr = "select * from employee where employeeName =" + ms;