i have started the java and just completed core java …but i am not able to proceed further because of the sqlException..
i have load the driver successfully and want to execute the query …but every time i found Exception how can i get rid of this problem…..
my code is as follows:
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);
}
this always shows : SQLException[Microsoft][ODBC Driver Manager] Invalid string or buffer length
plz help me..fnds
It could be caused by a zero length string as your sql login:
Connection con=DriverManager.getConnection(“Jdbc:Odbc:librarysystem”,”sa”,”sa_password”);