Byte array insert and retrieve
In this chapter you will learn:
Insert byte array and read byte array
String sql = "INSERT INTO mysql_all_table (col_binarystream) VALUES(?)";
PreparedStatement pstmt = connection.prepareStatement(sql);
//j a v a 2s . co m
byte[] buffer = "some data".getBytes();
pstmt.setBytes(1, buffer);
pstmt.executeUpdate();
pstmt.close();
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM mysql_all_table");
while (resultSet.next()) {
byte[] bytes = resultSet.getBytes("col_binarystream");
}
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » SQL Data Types