-1
created 2 classes one of connection and the other
how I could do a login/password validation with these two classes
connection
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package semeq;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author SpiriT
*/
public class ConnectionFactory {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost:3306/helpsemeq";
private static final String USER = "root";
private static final String PASS = "";
public static Connection getConnection(){
try {
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USER, PASS);
} catch (ClassNotFoundException | SQLException ex) {
throw new RuntimeException("Erro na conexão: ",ex);
}
}
public static void closeConnection(Connection con){
try {
if(con != null){
con.close();
}
}catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt){
closeConnection(con);
try {
if(stmt != null){
stmt.close();
}
}catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt, ResultSet rs){
closeConnection(con, stmt);
try {
if(rs != null){
rs.close();
}
}catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
dao
package semeq;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class daoSemeq {
private ResultSet rs;
private Statement stm;
private Connection conn = ConnectionFactory.getConnection();
public daoSemeq (){
}
public ResultSet getUserDAO () throws SQLException{
this.stm = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
this.rs = stm.executeQuery("SELECT login,senha FROM usuário");
return this.rs;
}
}
my doubt and how I would cosneguiria to do a validation in the form to check the login and the password entered.