private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(count<3)
{
try
{
conn = DbConnection.ConnectDB();
ps=conn.prepareStatement("select * from LOGIN_TBL where USERNAME='"+value1+"' and PASSWORD='"+value2+"'");
ps.setString(1,jTextField1.getText());
ps.setString(2,jPasswordField1.getText());
ResultSet rs=ps.executeQuery();
if(rs.next())
{
uname=rs.getString("USERNAME");
pass=rs.getString("PASSWORD");
}
if(value1.equals(uname) && value2.equals(pass))
{
String str = "Dear " + jTextField1.getText() + ".\nWelcome ";
JOptionPane.showMessageDialog(null,str, "Welcome", JOptionPane.INFORMATION_MESSAGE );
d.setVisible(true);
}
else if(value1.equals("") || value2.equals(""))
{
JOptionPane.showMessageDialog(null,"UserId OR Password cannot be empty!","Error",JOptionPane.ERROR_MESSAGE);
jTextField1.requestFocus();
}
else if (!value1.equals(uname) || !value2.equals(pass))
{
JOptionPane.showMessageDialog(null,"Please enter correct UserId or Password!","Error",JOptionPane.ERROR_MESSAGE);
jTextField1.setText("");
jPasswordField1.setText("");
jTextField1.requestFocus();
}
}
catch(Exception e)
{
System.out.println(e);
}
count++;
}
}
this is my login form
public class DbConnection {
static Connection conn=DbConnection.ConnectDB();
static Statement st;
static Statement rs;
public static Connection ConnectDB(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection ("jdbc:odbc:INVENTORY_MNGT");
JOptionPane.showMessageDialog(null, "Connected");
return conn;
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
this is connection class
but when i run the login form, it the form opens but when i click on login button gives an null pointer exception.....just wanted to know what my error is

New Topic/Question
Reply



MultiQuote






|