我已经启动了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驱动程序管理器]无效的字符串或缓冲区长度
PLZ帮我......发送
答案 0 :(得分:0)
这可能是由sql登录的零长度字符串引起的:
Connection con = DriverManager.getConnection(“Jdbc:Odbc:librarysystem”,“sa”,“sa_password”);