ResultSet getBinaryStream Example
ResultSet Interface getBinaryStream example. This example shows you how to use getBinaryStream method.
ResultSet Interface getBinaryStream example. InputStream getBinaryStream(String columnLabel) throws SQLException Retrieves the value of the designated column in the current row of this ResultSet object as a stream of uninterpreted bytes. The value can then be read in chunks from the stream. This method is particularly suitable for retrieving large LONGVARBINARY values.
Here is the code
/*
* @ # GetBinaryStream1.java
* A class repersenting use to getBinaryStream method
* of ResultSet in java.sql package
* version 01 July 2008
* author Rose India
*/
import java.io.*;
import java.sql.*;
public class GetBinaryStream1 {
public static void main(String[] args) throws Exception {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String name = null;
InputStream stream = null;
BufferedReader br = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.59:3306/";
String db = "Student";
Class.forName(driver);
con = DriverManager.getConnection(url + db, "root", "root");
try {
String sql = "Select * from stu_info";
st = con.createStatement();
rs = st.executeQuery(sql);
while (rs.next()) {
stream = rs.getBinaryStream("name");
br = new BufferedReader(new InputStreamReader(stream));
while ((name = br.readLine()) != null) {
System.out.println(name);
}
}
} catch (Exception e) {
System.out.println(e);
}
}
} |
Output
Mahendra
Ravi
komal
Ravi1 |
|