Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 datosn:"+ ex,"Error", JOptionPane.ERROR_MESSAGE);
- }
- return cnx;
- }
- public void closeCnx() throws SQLException{
- if(cnx != null){
- cnx.close();
- }
- }
- 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();
- }
Add Comment
Please, Sign In to add comment