Bom eu tenho esse button :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ConnectionFactory con = new ConnectionFactory();
String login = tLogin.getText();
String senha = tSenha.getText();
String query = "SELECT Login, Senha FROM login WHERE Login='"+login+"' and Senha='"+senha+"'";
con = null;
Statement statement = null;
statement = con.getConnection().createStatement();
try{
ResultSet resultSet = statement.executeQuery(query);
while(resultSet.next()){
String logindb = resultSet.getString(1);
String senhadb = resultSet.getString(2);
if ((senha == senhadb) || (login == logindb)){
return (1);
}
}
}
catch (SQLException sqlException){}
}
mas estou com problema nessa linha…
statement = con.getConnection().createStatement();
(unreported exception SqlException)
a minha class de conexão:
package semeqapp;
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;
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);
}
}
}