Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- btnLogIn.addActionListener(new ActionListener() {
- @SuppressWarnings({ "deprecation" })
- public void actionPerformed(ActionEvent arg0) {
- // creating connection and query variables
- Connection conn = null;
- ResultSet rs = null;
- PreparedStatement pst = null;
- String url = "jdbc:mysql://MY.DB.URL/*******";
- //load the driver
- try {
- Class.forName("com.mysql.jdbc.Driver");
- // making connection
- conn = DriverManager.getConnection(url, "*******", "*******");
- // query
- String sql = "select * from log_in where username = ? and pssword = ?";
- pst = conn.prepareStatement(sql);
- pst.setString(1, UsernameField.getText());
- pst.setString(2, PasswordField.getText());
- rs = pst.executeQuery(sql);
- if(rs.next()){
- //Retrieve by column name
- String username = rs.getString("username");
- System.out.println("Username : " + username);
- String password = rs.getString("pssword");
- System.out.println("Password : " + password);
- lblLog_In.setText("Welcome.");
- } else {
- lblLog_In.setText("ERROR: invalid log in information.");
- }
- } catch (SQLException e) {
- System.out.println("SQL Exception.");
- } catch (ClassNotFoundException e) {
- System.out.println("Class not found exception.");
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement