Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package modelo;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.sql.*;
- public class Registro {
- // ------------------------------ FIELDS ------------------------------
- private int cedula;
- private String classfor = "oracle.jdbc.driver.OracleDriver";
- private String clave = "campofe3750319";
- private Connection con = null;
- private String foto;
- private InputStream imagen;
- private String nombre;
- private PreparedStatement pr = null;
- private ResultSet rs = null;
- private String url = "jdbc:oracle:thin:@localhost:1521:XE";
- private String usuario = "root";
- // --------------------- GETTER / SETTER METHODS ---------------------
- public int getCedula() {
- return cedula;
- }
- public void setCedula(int cedula) {
- this.cedula = cedula;
- }
- public String getFoto() {
- return foto;
- }
- public void setFoto(String foto) {
- this.foto = foto;
- }
- public InputStream getImagen() {
- return imagen;
- }
- public void setImagen(InputStream imagen) {
- this.imagen = imagen;
- }
- public String getNombre() {
- return nombre;
- }
- public void setNombre(String nombre) {
- this.nombre = nombre;
- }
- // -------------------------- OTHER METHODS --------------------------
- public void insertar(int cedula, String nombre, String foto) {
- String sql = "Insert into datos values(?,?,?)";
- try {
- Class.forName(classfor);
- con = DriverManager.getConnection(url, usuario, clave);
- /*
- PreparedStatement stmt = con.prepareStatement("CREATE TABLE datos (ID INT PRIMARY KEY, NOMBRE VARCHAR(64))");
- stmt.execute();
- stmt.close();
- */
- File archivo = new File("C:\\Users\\SKIMO\\Pictures\\wallpapers" + foto);
- FileInputStream entrada = new FileInputStream(archivo);
- pr = con.prepareStatement(sql);
- pr.setInt(1, cedula);
- pr.setString(2, nombre);
- pr.setBinaryStream(3, entrada, (int) archivo.length());
- pr.executeUpdate();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- private void commit() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement