📄 e260. getting and inserting binary data into an database table.txt
字号:
This example inserts and retrieves binary data into the table created in e248 Creating a MySQL Table to Store Java Types.
try {
// Prepare a statement to insert binary data
String sql = "INSERT INTO mysql_all_table (col_binarystream) VALUES(?)";
PreparedStatement pstmt = connection.prepareStatement(sql);
// Create some binary data
byte[] buffer = "some data".getBytes();
// Set value for the prepared statement
pstmt.setBytes(1, buffer);
// Insert the data
pstmt.executeUpdate();
pstmt.close();
// Select records from the table
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM mysql_all_table");
while (resultSet.next()) {
// Get data from the binary column
byte[] bytes = resultSet.getBytes("col_binarystream");
}
} catch (SQLException e) {
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -