ResultSet getArray Example

ResultSet Interface getAsciiStream example. This example shows you how to use getAsciiStream method.


ResultSet Interface getAsciiStream example. InputStream getAsciiStream(int columnIndex) throws SQLException Retrieves the value of the designated column in the current row of this ResultSet object as a stream of ASCII characters. The value can then be read in chunks from the stream. This method is particularly suitable for retrieving large LONGVARCHAR values. The JDBC driver will do any necessary conversion from the database format into ASCII.

Here is the code
/*
 * @ # GetAsciiStream.java
 * A class repersenting use to getAsciiStream method 
 * of ResultSet in java.sql package
 * version 01 July 2008
 * author Rose India 
 */

import java.io.*;
import java.sql.*;

public class GetAsciiStream {

  public static void main(String[] argsthrows 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.getAsciiStream(2);
        br = new BufferedReader(new InputStreamReader(stream));

        while ((name = br.readLine()) != null) {
          System.out.println(name);
        }
      }
      stream.close();
      br.close();

      rs.close();
      st.close();
      con.close();
    catch (Exception e) {
      System.out.println(e);
    }
  }
}

Output
Mahendra
Ravi
komal
Ravi1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US