Advertisement
skimo_321

Untitled

Jun 3rd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1.  
  2.  
  3. package modelo;
  4.  
  5.  
  6. import java.io.File;
  7. import java.io.FileInputStream;
  8. import java.io.InputStream;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.PreparedStatement;
  12. import java.sql.ResultSet;
  13.  
  14.  
  15.  
  16.  
  17. public class registro {
  18.  
  19.  
  20. private int cedula;
  21. private String nombre;
  22. private String foto;
  23. private InputStream imagen;
  24.  
  25.  
  26.  
  27. private String classfor="oracle.jdbc.driver.OracleDriver";
  28. private String url="jdbc:oracle:thin:@localhost:1521:XE";
  29. private String usuario="root";
  30. private String clave="campofe3750319";
  31.  
  32. private Connection con=null;
  33. private PreparedStatement pr=null;
  34. private ResultSet rs=null;
  35.  
  36.  
  37. public void insertar (int cedula, String nombre, String foto){
  38.  
  39.  
  40.  
  41. String sql="Insert into datos values(?,?,?)";
  42.  
  43. try{
  44. Class.forName(classfor);
  45. con=DriverManager.getConnection(url,usuario,clave);
  46.  
  47. if(con != null){
  48. con.close();
  49. }
  50.  
  51. File archivo=new File("C:\\Users\\SKIMO\\Pictures\\wallpapers"+foto);
  52. FileInputStream entrada=new FileInputStream(archivo);
  53.  
  54. pr=con.prepareStatement(sql);
  55.  
  56. pr.setInt(1,cedula);
  57. pr.setString(2, nombre);
  58. pr.setBinaryStream(3, entrada, (int)archivo.length());
  59.  
  60.  
  61.  
  62. pr.executeUpdate();
  63.  
  64.  
  65.  
  66.  
  67. }catch(Exception e){
  68. System.err.println(e);
  69.  
  70. }
  71.  
  72.  
  73.  
  74. }
  75.  
  76. public int getCedula() {
  77. return cedula;
  78. }
  79.  
  80. public void setCedula(int cedula) {
  81. this.cedula = cedula;
  82. }
  83.  
  84. public String getNombre() {
  85. return nombre;
  86. }
  87.  
  88. public void setNombre(String nombre) {
  89. this.nombre = nombre;
  90. }
  91.  
  92. public String getFoto() {
  93. return foto;
  94. }
  95.  
  96. public void setFoto(String foto) {
  97. this.foto = foto;
  98. }
  99.  
  100. public InputStream getImagen() {
  101. return imagen;
  102. }
  103.  
  104. public void setImagen(InputStream imagen) {
  105. this.imagen = imagen;
  106. }
  107.  
  108. private void commit() {
  109. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement