Advertisement
Guest User

AD2

a guest
Jan 3rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. package biblioteca;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. import javax.swing.JOptionPane;
  9.  
  10. /**
  11. *
  12. * @author Ana Calero
  13. */
  14. public class Biblioteca {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) throws SQLException {
  20. String strOpcion;
  21. boolean condicion = false;
  22. int opcion = 0;
  23. try {
  24. Class.forName("jdbc:odbc:admdb:accb");
  25. // Establecemos la conexión
  26. } catch (ClassNotFoundException ex) {
  27. Logger.getLogger(Biblioteca.class.getName()).log(Level.SEVERE, null, ex);
  28. }
  29.  
  30. do{
  31. strOpcion = JOptionPane.showInputDialog("__MENU__\n1.Crear Tabla Libros\n2.Crear Tabla Socios\n3.Insertar datos Tabla Libros\n4.Insertar datos Tabla Socios\n5.Recuperar datos Tabla Libros\n6. Recuperar datos Tabla Socios\n7. Consulta Actualización Libros\n8. Consulta Actualización Socios\n9. Consulta2 Actualización Libros\n10. Mostrar todos apartados\n0. Salir del programa");
  32. try{
  33. opcion = Integer.parseInt(strOpcion);
  34. }catch (NumberFormatException ex){
  35. JOptionPane.showMessageDialog(null, "Error, solo puede introducir números");
  36. opcion = 0;
  37. }
  38.  
  39. switch(opcion){
  40. case 0:
  41. System.out.println("Fin del programa");
  42. break;
  43.  
  44. case 1:
  45. Connection con =DriverManager.getConnection("jdbc:ucanaccess//Biblioteca.mdb");
  46. Statement stmt = con.createStatement();
  47. String sqlStr="CREATE TABLE Libros"
  48. +"ISBN integer not null,"
  49. +"Titulo varchar(50),"
  50. +"NombreAutor varchar (25),"
  51. +"NumeroEjemplares integer,"
  52. +"Editorial varchar(25),"
  53. +"NumeroPaginas integer,"
  54. +"PRIMARY KEY (ISBN)";
  55. stmt.execute(sqlStr);
  56. condicion=true;
  57. break;
  58.  
  59. case 2:
  60. Connection con =DriverManager.getConnection("jdbc:ucanaccess//Biblioteca.mdb");
  61. Statement stmt = con.createStatement();
  62. String sql="CREATE TABLE Socios"
  63. +"DNI varchar (10) not null,"
  64. +"Nombre varchar(25),"
  65. +"Apellidos varchar (50),"
  66. +"Edad integer,"
  67. +"Dirección varchar(50),"
  68. +"Telefono varchar(9),"
  69. +"PRIMARY KEY (DNI)";
  70. stmt.execute(sql);
  71. condicion=true;
  72. break;
  73.  
  74. case 3:
  75.  
  76. condicion=true;
  77. break;
  78.  
  79. case 4:
  80.  
  81. condicion=true;
  82. break;
  83.  
  84. case 5:
  85.  
  86. condicion=true;
  87. break;
  88.  
  89. case 6:
  90.  
  91. condicion=true;
  92. break;
  93.  
  94. case 7:
  95.  
  96. condicion=true;
  97. break;
  98.  
  99. case 8:
  100.  
  101. condicion=true;
  102. break;
  103.  
  104. case 9:
  105.  
  106. condicion=true;
  107. break;
  108.  
  109. case 10:
  110.  
  111. condicion=true;
  112. break;
  113.  
  114.  
  115. default:JOptionPane.showMessageDialog(null, "Opción no válida");
  116. }
  117. }while(condicion = false);
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement