Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int column = jTable1.getColumnModel().getColumnIndexAtX(evt.getX());
- int row = evt.getY()/jTable1.getRowHeight();
- if(row < jTable1.getRowCount() && row>=0 && column < jTable1.getColumnCount() && column >=0){
- Object value = jTable1.getValueAt(row, column);
- if(value instanceof JButton){
- ((JButton)value).doClick();
- JButton boton = (JButton) value;
- System.out.println("Click");
- if(boton.getName().equals("R")){
- System.out.println("Boton Insertar");
- try{
- JOptionPane.showMessageDialog(null,"Voto Realizado");
- String query = "insert into voto(codigoVoto,horaVoto,codigoEstudiante,codigoCandidato)values(?,?,?,?)";
- PreparedStatement a=conexion.prepareStatement(query);
- a.setString(1,codigo.getText());
- a.setString(2,horaVoto.getText());
- a.setString(3,estudiante.getText());
- a.setString(4,codigoCandidato.getText());
- a.executeUpdate();
- JOptionPane.showMessageDialog(null,"Su voto fue registrado");
- }
- catch(HeadlessException | SQLException e){
- JOptionPane.showMessageDialog(null,e);
- }
- }
- }
- }
- }
- static PreparedStatement prepareStatement(String query) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public String db="votsi";
- public String Url="Jdbc:mysql://localhost:3306/"+db;
- public String User="root";
- public String Clave="";
- public conexion(){
- }
- public Connection conectar(){
- Connection link=null;
- try{
- Class.forName("org.gjt.mm.mysql.Driver");
- link=DriverManager.getConnection(this.Url,this.User,this.Clave);
- }
- catch(ClassNotFoundException | SQLException e){
- JOptionPane.showMessageDialog(null,e);
- }
- return link
Add Comment
Please, Sign In to add comment