Guest User

Untitled

a guest
Jun 6th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package my.boletas;
  7. import javax.swing.JOptionPane;
  8. import java.sql.Statement;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. /**
  14. *
  15. * @author skypce
  16. */
  17. public class baseDatos {
  18. public Connection conexion=null;
  19. public Statement st = null;
  20.  
  21.  
  22. /*public baseDatos(String nombreDB) throws ClassNotFoundException, SQLException{
  23. Class.forName("org.sqlite.JDBC");
  24. this.conexion = DriverManager.getConnection("jdbc:sqlite:" + nombreDB);
  25. this.st = this.conexion.createStatement();
  26. }*/
  27.  
  28.  
  29. public baseDatos(){
  30.  
  31.  
  32. try {
  33. Class.forName("org.sqlite.JDBC");
  34. conexion = DriverManager.getConnection("jdbc:sqlite:negocio.sqlite");
  35. st = conexion.createStatement();
  36. }catch(Exception e){
  37. JOptionPane.showMessageDialog(null, "No se encontro el controlador");
  38. System.exit(1);
  39. }
  40.  
  41. }
  42. /*try{
  43. st=conexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  44. }catch (Exception e){
  45. JOptionPane.showMessageDialog(null, "Error al crear objeto sentencia");
  46. }
  47. }*/
  48. public synchronized ResultSet ejecutarSelect (String la_sql){
  49. ResultSet rs=null;
  50. try {
  51. rs=st.executeQuery (la_sql);
  52.  
  53. }catch (Exception e){
  54. System.out.print(e);
  55. }
  56.  
  57. return rs;
  58.  
  59.  
  60. }
  61. public synchronized int ejecutarSql (String la_sql){
  62. int num_filas=0;
  63. try {
  64. num_filas=st.executeUpdate(la_sql);
  65.  
  66. }catch (Exception e){
  67. System.out.print(e);
  68. }
  69.  
  70. return num_filas;
  71. }
  72. public synchronized void closedb (){
  73.  
  74. try{
  75. conexion.close();
  76.  
  77. //conexion.close();
  78. }catch (Exception e){
  79. System.out.print(e);
  80. }
  81. }
  82. }
Add Comment
Please, Sign In to add comment