-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
34 lines (25 loc) · 933 Bytes
/
Main.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
package com.jdbc.practice;
import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class Main {
public static void main(String[] args) {
try {
Connection c = ConnectionProvider.getConnection();
String q = "insert into images(pic) values(?)";
PreparedStatement pmt = c.prepareStatement(q);
JFileChooser jf = new JFileChooser();
jf.showOpenDialog(null);
File file = jf.getSelectedFile();
FileInputStream fis = new FileInputStream(file);
pmt.setBinaryStream(1,fis,fis.available());
pmt.executeUpdate();
System.out.println("done");
JOptionPane.showMessageDialog(null,"success");
} catch (Exception e){
e.printStackTrace();
}
}
}