This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/11/26

db error

divinity divinity

2017/11/26

#
i trying my hand at this program called Crime Scene Investigation: I have just did the login screen. I want to use a database to login to validate the users but i am getting this errors with the codes that I used.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;

public class CrimeSceneInvestigation extends javax.swing.JFrame {

  
    public CrimeSceneInvestigation() {
        initComponents();
        
    }
  private void jButton_CancelActionPerformed(java.awt.event.ActionEvent evt) {                                               
    this.dispose();
    }                                              

    private void jButton_submitActionPerformed(java.awt.event.ActionEvent evt) {                                               
       if(jTextField_username.getText().length() == 0){
            JOptionPane.showMessageDialog(null, "empty credentials detected, fill it up ");
       }
       else if(jPasswordField_passwrd.getPassword().length == 0){
           JOptionPane.showMessageDialog(null, "empty credential detected, please fill it up");
       }
       else{
           
            String user = jTextField_username.getText();// getting the input
            char[] pass = jPasswordField_passwrd.getPassword();//getting the input
            String pwd = String.copyValueOf(pass);
            if(validate_login(user, pwd)){
                
                JOptionPane.showMessageDialog(null, "Valid login credentials");
            }
            else{
                
                JOptionPane.showMessageDialog(null, "Invlaid long credentials");
            }
       }
        
    }
    private boolean validate_login(String user, String pwd) {
       try{
           
           Class.forName("com.mysql.jdbc.Driver");// db connection
           Connection conn  =DriverManager.getConnection("jdbc.mysql://localhost:3306/crime_Scene_investigation" , "dbuser","dbpass");
           PreparedStatement stmt = conn.prepareStatement("Select * from login where username AND password");
           stmt.setString(1, user);
           stmt.setString(2, pwd);
           ResultSet rs = stmt.executeQuery();
           if(rs.next()){
               
               return true;
           }
           else{
               
               return false;
           }
           
       }
       catch(Exception e){
           e.printStackTrace();
           
       }
       return false;
    }                                              

       Runnable() {
            @Override
            public void run() {
                new CrimeSceneInvestigation().setVisible(true);
                
            } 
        });
    }
and this is error am receiving when I tried to login
at 

CrimeSceneInvestigation.validate_login(CrimeSceneInvestigation.java:131)
	at CrimeSceneInvestigation.jButton_submitActionPerformed(CrimeSceneInvestigation.java:115)
	at CrimeSceneInvestigation.access$100(CrimeSceneInvestigation.java:8)
	at CrimeSceneInvestigation$2.actionPerformed(CrimeSceneInvestigation.java:80)
divinity divinity

2017/11/26

#
the error are at line 44, line 30, line 7 what is the error the and how can it be fixed
danpost danpost

2017/11/26

#
divinity wrote...
the error are at line 44, line 30, line 7 what is the error the and how can it be fixed
What class is line 44 supposed to be initializing? What happens if you just remove that line (is it really needed, there)?
divinity divinity

2017/11/27

#
hi danpost i graded it out just to see what happen, and it moved on to the next line in error.
divinity divinity

2017/11/27

#
do i have to download a mysql database connection library jar or something
danpost danpost

2017/11/27

#
divinity wrote...
i graded it out just to see what happen, and it moved on to the next line in error.
What error were you then getting?
You need to login to post a reply.