Guest User

Untitled

a guest
Oct 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Connection cn;
  2. Statement st;
  3. ResultSet rs;
  4. String con, nombre="jose", dia="lunes 28";
  5.  
  6.  
  7. public void conectar(){
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. cn=DriverManager.getConnection("jdbc:mysql://localhost/biblioteca?user=root&password=");
  11. System.out.println("Conexion");
  12. } catch (Exception e) {
  13. System.out.println(e.toString());
  14. e.printStackTrace();
  15. }
  16.  
  17. }
  18. public void cerrar() throws SQLException{
  19. cn.close();
  20. System.out.println("Cerrar");
  21. }
  22. public void insertar(String nombre, String dia){
  23. try {
  24. conectar();
  25. con="insert into tabla (nombre, dia) values ('"+nombre+"', '"+dia+"')";
  26. st.execute(con);
  27. System.out.println("Insertar good");
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31.  
  32. }
  33. public void insertar2(String nombre, String dia){
  34. try {
  35. conectar();
  36. con="insert into p (uno, dos) values ('"+nombre+"', '"+dia+"')";
  37. st.execute(con);
  38. System.out.println("Insertar good");
  39. } catch (SQLException e) {
  40. e.printStackTrace();
  41. }
  42.  
  43. }
  44. public void select(String nombre){
  45. try {
  46. conectar();
  47. con="select * from tabla where nombre='"+nombre+"'";
  48. rs=st.executeQuery(con);
  49. while(rs.next()){
  50. nombre=rs.getString("nombre");
  51. dia=rs.getString("dia");
  52. System.out.println("Select");
  53. }
  54.  
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. public static void main(String[] args) {
  60. // TODO code application logic here
  61. RegistroBiblio a=new RegistroBiblio();
  62. a.insertar("Jose", "Jueves");
  63. }
Add Comment
Please, Sign In to add comment