Guest User

Untitled

a guest
Feb 7th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. int column = jTable1.getColumnModel().getColumnIndexAtX(evt.getX());
  2. int row = evt.getY()/jTable1.getRowHeight();
  3.  
  4. if(row < jTable1.getRowCount() && row>=0 && column < jTable1.getColumnCount() && column >=0){
  5. Object value = jTable1.getValueAt(row, column);
  6.  
  7. if(value instanceof JButton){
  8. ((JButton)value).doClick();
  9. JButton boton = (JButton) value;
  10. System.out.println("Click");
  11.  
  12.  
  13. if(boton.getName().equals("R")){
  14. System.out.println("Boton Insertar");
  15.  
  16. try{
  17. JOptionPane.showMessageDialog(null,"Voto Realizado");
  18. String query = "insert into voto(codigoVoto,horaVoto,codigoEstudiante,codigoCandidato)values(?,?,?,?)";
  19. PreparedStatement a=conexion.prepareStatement(query);
  20. a.setString(1,codigo.getText());
  21. a.setString(2,horaVoto.getText());
  22. a.setString(3,estudiante.getText());
  23. a.setString(4,codigoCandidato.getText());
  24. a.executeUpdate();
  25. JOptionPane.showMessageDialog(null,"Su voto fue registrado");
  26.  
  27. }
  28. catch(HeadlessException | SQLException e){
  29. JOptionPane.showMessageDialog(null,e);
  30. }
  31.  
  32.  
  33. }
  34.  
  35. }
  36. }
  37. }
  38.  
  39. static PreparedStatement prepareStatement(String query) {
  40. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  41.  
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. public String db="votsi";
  50. public String Url="Jdbc:mysql://localhost:3306/"+db;
  51. public String User="root";
  52. public String Clave="";
  53.  
  54. public conexion(){
  55.  
  56. }
  57.  
  58. public Connection conectar(){
  59. Connection link=null;
  60. try{
  61. Class.forName("org.gjt.mm.mysql.Driver");
  62. link=DriverManager.getConnection(this.Url,this.User,this.Clave);
  63. }
  64. catch(ClassNotFoundException | SQLException e){
  65. JOptionPane.showMessageDialog(null,e);
  66.  
  67. }
  68. return link
Add Comment
Please, Sign In to add comment