I was creating my querys and suddenly
The issue is that I can not continue with the development of my program
I leave the code of my connection
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class Conexion {
Connection cnx;
public Connection getCnx(){
try {
Class.forName("com.mysql.jdbc.Driver");
cnx=DriverManager.getConnection("jdbc:mysql://localhost:3306/myl", "root", "");
}catch (ClassNotFoundException | SQLException ex) {
JOptionPane.showMessageDialog(null,"Error de Acceso:\n No hay conexion a la base de datos\n:"+ ex,"Error", JOptionPane.ERROR_MESSAGE);
}
return cnx;
}
public void closeCnx() throws SQLException{
if(cnx != null){
cnx.close();
}
}
}
and this is the code of my query
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
public class Querys {
Conexion CNX=new Conexion();
PreparedStatement SQL;
List validation = new ArrayList();
Connection con = CNX.getCnx();
Object[] titulos = {"id","nombre","tipo","fecha","hora"};
DefaultTableModel dtm = new DefaultTableModel(null,titulos);
public List LogIn(String user) throws SQLException, IOException, ClassNotFoundException {
String queryPassword = "SELECT users, pass FROM log WHERE users='"+user+"'";
SQL = con.prepareStatement(queryPassword);
ResultSet result = SQL.executeQuery();
String PassDB = null;
String UserDB = null;
if (result.next()){
UserDB=result.getString("users");
PassDB=result.getString("pass");
validation.add(UserDB);
validation.add(PassDB);
}
CNX.closeCnx();
return validation;
}
public DefaultTableModel buscarTorneo(String fecha) throws SQLException, IOException, ClassNotFoundException {
String queryPassword = "SELECT * FROM 'torneo' WHERE fecha='"+fecha+"'";
SQL = con.prepareStatement(queryPassword);
ResultSet result = SQL.executeQuery();
if (result.next()){
dtm.addRow(new Object[]{
result.getString("id"),
result.getString("nombre"),
result.getString("tipo"),
result.getString("fecha"),
result.getString("hora")
});
}
CNX.closeCnx();
return dtm;
}
public void crearTorneo(String nombre,String tipo, String fecha,String h) throws SQLException, IOException, ClassNotFoundException{
String query = "INSERT INTO torneo (nombre, tipo, fecha, hora) "
+ "VALUES ('"+nombre+"','"+tipo+"','"+fecha+"','"+h+"');";
SQL = con.prepareStatement(query);
SQL.execute();
CNX.closeCnx();
}
}
I hope you can help me as I searched everywhere but I can not find concise information about it.
Geacias