2012-07-19 141 views
0

我已经启动了Java并刚刚完成了核心Java ...但我无法继续进行,因为sqlException .. 我已成功加载驱动程序并希望执行查询...但我每次发现异常时我怎样才能摆脱这个问题的.....SQL异常无效的字符串或缓冲区长度

我的代码如下:

if(e.getSource()==b1) 
    { 
     if(t1.getText().equals("")) 
     { 
      JOptionPane.showMessageDialog(null,"provide username to login"); 
      t1.requestFocus(); 
     } 
     else if(t2.getText().equals("")) 
     { 
      JOptionPane.showMessageDialog(null,"provide password to login"); 
      t2.requestFocus(); 
     } 
     else 
     { 
      String tablename=null; 
      if(rb==1) 
      {tablename="Admin";} 
      else if(rb==2) 
      {tablename="Clerks";} 
      else if(rb==3) 
      {tablename="members";} 
       try 
       { 
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
        Connection con=DriverManager.getConnection("Jdbc:Odbc:librarysystem","",""); 
        PreparedStatement ps=con.prepareStatement("select * from "+tablename+" where username=? and password=?"); 
        ps.setString(1,t1.getText()); 
        ps.setString(2,t2.getText()); 
        ResultSet rs=ps.executeQuery(); 
        if(rs.next()) 
        { 
         //System.out.println(res); 
         //JOptionPane.showMessageDialog(new JFrame(),"Registered user successful"); 
         l=new library(); 
        } 
        else 
        { 
         JOptionPane.showMessageDialog(new JFrame(),"wrong details entered"); 
        } 
       } 
       catch(Exception sql) 
       { 

        t1.setText (""); 
        t2.setText (""); 
        t1.requestFocus(); 
        System.out.println(sql); 
        JOptionPane.showMessageDialog (null, "Incorrect excep Information Provided."); 
       } 
     } 
    } 
    else if(e.getSource()==jrb1) 
    { 
     rb=1; 
    } 
    else if(e.getSource()==jrb2) 
    { 
     rb=2; 
    } 
    else if(e.getSource()==jrb3) 
    { 
     rb=3; 
    } 
    else if(e.getSource()==b2) 
    { 
     f.setVisible(false); 
     f.dispose(); 
     System.exit(152); 
    } 

这总是显示:的SQLException [微软] [ODBC驱动程序Manager]无效的字符串或缓冲区长度

个plz帮助me..fnds

+0

'Jdbc:Odbc'应该替换为'jdbc:odbc'。 – 2013-05-06 14:51:43

回答

0

它可以通过一个零长度字符串引起作为您的SQL登录:

连接CON =的DriverManager.getConnection(为 “jdbc:ODBC:librarysystem”, “山”,“sa_password “);

相关问题