我已经启动了java并且刚刚完成了核心java ...但由于sqlException我无法继续进行。我已经成功加载驱动程序并想要执行查询...但是每次我发现异常怎么能我摆脱了这个问题......
我的代码如下:
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[Microsoft][ODBC Driver Manager] Invalid string or buffer length
请帮助我..fnds