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
'Jdbc:Odbc'應該替換爲'jdbc:odbc'。 – 2013-05-06 14:51:43