Guest User

Untitled

a guest
Dec 11th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. {
  2.  
  3.  
  4. try
  5. {
  6. texto1=txt1.getText().trim();
  7. texto2=txt2.getText().trim();
  8. texto3=Integer.parseInt(txt3.getText().trim());
  9. paso=true;
  10. }
  11. catch(Exception e2)
  12. {
  13.  
  14. JOptionPane.showMessageDialog(null,"Debe rellenar los campos");
  15. paso=false;
  16. }
  17. if(paso==true)
  18. {
  19. modelo = new DefaultListModel();
  20. try
  21. {
  22. Connection conexion=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=menu","sa","sa");
  23.  
  24. consulta=conexion.prepareStatement("INSERT INTO ALMACENAR VALUES(?,?,?)");
  25.  
  26. consulta.setString(1, texto1);
  27. consulta.setString(2,texto2);
  28. consulta.setInt(3, texto3);
  29. consulta.executeUpdate();
  30. JOptionPane.showMessageDialog(null, "Datos ingresados correctamente");
  31. txt1.setText("");
  32. txt2.setText("");
  33. txt3.setText("");
  34. consulta.close();
  35.  
  36. try
  37. {
  38. conexion=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=menu","sa","sa");
  39.  
  40. statement=conexion.createStatement();
  41. //recorrer bd
  42. String pedir="SELECT DISTINCT nombre,apellido FROM almacenar order by nombre";
  43.  
  44. resulset=statement.executeQuery(pedir);
  45. while(resulset.next())
  46. {
  47. modelo.addElement(resulset.getString(1));
  48.  
  49. }
  50. resulset.close();
  51. lista.setModel(modelo);
  52. }
  53. catch(Exception error)
  54. {
  55. error.printStackTrace();
  56. }
  57.  
  58.  
  59. JOptionPane.showMessageDialog(null,"Usuario registrado Satisfactoriamente");
  60.  
  61.  
  62. }
  63. catch(Exception ex)
  64. {
  65. JOptionPane.showMessageDialog(null, "Este nombre ya esta en uso");
  66. //ex.printStackTrace();
  67.  
  68. }
  69.  
  70. }
  71. }
Add Comment
Please, Sign In to add comment