📄 createimageblob1.java~7~
字号:
package cmp2image;
import java.sql.*;
import java.io.*;
public class CreateImageBlob1 {
public static void main(String[] args) throws Exception {
String dbUrl = "jdbc:mysql://127.0.0.1/mydb1";
String user = "";
String password = "";
File file;
FileInputStream fis;
PreparedStatement pstmt;
String insertSQL;
// Load the driver
Class.forName("com.mysql.jdbc.Driver");
//connecting the databse
Connection con = DriverManager.getConnection(
dbUrl, user, password);
/*String createTable = "CREATE TABLE Flower" +
" (Name VARCHAR(250) NOT NULL PRIMARY KEY, "+
" IMGBYTES BLOB )";
Statement s = con.createStatement();
s.executeUpdate(createTable);
String insertSQL = "Insert INTO Flower(Name,IMGBYTES) "+
" VALUES(?,?)";
pstmt = con.prepareStatement(insertSQL);
System.out.println("Connection OK");
file = new File("D:\\WebDesignCodes\\MyPlants\\images\\FlowerAfricanOrchid.jpg");
fis = new FileInputStream(file);
pstmt.setString(1, "AfricanOrchid");
pstmt.setBinaryStream(2, fis, (int) file.length());
pstmt.executeUpdate();
*/
insertSQL = "Insert INTO Flower(Name,IMGBYTES) " +
" VALUES(?,?)";
pstmt = con.prepareStatement(insertSQL);
file = new File(
"D:\\WebDesignCodes\\MyPlants\\images\\FlowerBabyBreath.jpg");
fis = new FileInputStream(file);
pstmt.setString(1, "BabyBreath");
pstmt.setBinaryStream(2, fis, (int) file.length());
pstmt.executeUpdate();
/* insertSQL = "Insert INTO Flower(Name,IMGBYTES) "+
" VALUES(?,?)";
pstmt = con.prepareStatement(insertSQL);
file = new File("D:\\WebDesignCodes\\MyPlants\\images\\FlowerBlackEyedSusan.jpg");
fis = new FileInputStream(file);
pstmt.setString(1, "BlackEyedSusan");
pstmt.setBinaryStream(2, fis, (int) file.length());
pstmt.executeUpdate();
*/
pstmt.close();
con.close();
fis.close();
System.out.println("Image Insert Successful");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -