1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Java login with Java Derby

Discussion in 'Software Development' started by ahamed, Feb 6, 2015.

Thread Status:
Not open for further replies.
  1. ahamed

    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..
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1142584

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice