-
Notifications
You must be signed in to change notification settings - Fork 1
/
inderttry.java
79 lines (69 loc) · 2.43 KB
/
inderttry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package wfes;
import dal.ConnectionDAL;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.rmi.CORBA.Util;
/**
*
* @author hp pav 15-e015tx
*/
public class inderttry {
void insertdata() {
try {
PreparedStatement preparedStatement = new ConnectionDAL().getConnection().prepareStatement("INSERT INTO `wfes`.`imagetry` (`FILE_NAME`) VALUES (?)");
File fBlob = new File("C:\\Users\\hp pav 15-e015tx\\Documents\\new.pdf");
FileInputStream is = new FileInputStream(fBlob);
preparedStatement.setBinaryStream(1, is, (int) fBlob.length());
preparedStatement.execute();
} catch (Exception ex) {
ex.printStackTrace();
}
}
void retrievedata() {
Statement statement;
try {
statement = new ConnectionDAL().getConnection().createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM `wfes`.`imagetry`");
InputStream val = null;
while (rs.next()) {
val = rs.getBinaryStream(2);
}
File fBlob1 = new File("C:\\Users\\hp pav 15-e015tx\\Documents\\out.pdf");
try {
FileOutputStream os = new FileOutputStream(fBlob1);
byte[] buffer = new byte[1024];
int bytesRead;
//read from is to buffer
while ((bytesRead = val.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
val.close();
//flush OutputStream to write any buffered data to file
os.flush();
os.close();
// while (val.read() != -1) {
// os.write(val.read());
// }
} catch (Exception ex) {
ex.printStackTrace();
}
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}