Solved: Java login with Java Derby

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

ahamed

Thread Starter
Joined
Dec 8, 2014
Messages
7
This is my database connection class

Code:
import java.sql.*;

public class connectWithDB {
  

public static void DBconnection(){
    
  Connection conn = null;
  
  String url = "jdbc:derby://localhost:1527/";
  String dbName = "MyTinyShopDB";
  String driver = "org.apache.derby.jdbc.ClientDriver";
  String userName = "root"; 
  String password = "root";
  
  try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);

  //conn.close();
 
  } 
   
 catch (Exception e)
 {
  e.printStackTrace();
  }
  
 }

}
This is code for login button

Code:
    private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                         
   Connection conn = null;
   PreparedStatement prestmnt = null;
   ResultSet Reltset = null;
   
        
       try {
           String sql = "SELECT * FROM LOGINDETAILS WHERE LOGINID='"+txtFieldUserName.getText()+"'AND USERPASSWORD='"+txtFieldPassword.getText()+"'";
           prestmnt=conn.prepareStatement(sql);
           Reltset=prestmnt.executeQuery();
           
           if (Reltset.next()){
           
           AdminMainForm adminform = new AdminMainForm();
           adminform.setVisible(true);
           }
           
           else
           {
           JOptionPane.showMessageDialog(null, "User Name or Password is Wrong");
           }
           
           
       } catch (SQLException ex) {
           Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
       }
          
    }
Program is running but when i click the login button these errors appears in netbeans

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at mytinyshop.Login.btnLoginActionPerformed(Login.java:159)
at mytinyshop.Login.access$200(Login.java:18)
at mytinyshop.Login$3.actionPerformed(Login.java:77)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)

and more errors

i have added user name and password in database it has to check the database if the username and passsword are correct it has to goto the other form otherwise it has to show wrong password dialog please someone help me..
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top