用jdbc对于SQLSERVER中读取ntext字段所采用的方法

package com.aptech;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.*;

public class HelloWorld {

 public static void main(String[] args) {
  Connection con;
  Statement stmt;
  String url;
  String sql;

  try {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  } catch (ClassNotFoundException ce) {
   System.out.println(ce);
  }

  try {
   url = "jdbc:odbc:test";
   con = DriverManager.getConnection(url, "sa", "");
   sql = "select *  from java";
   stmt = con.createStatement();
   ResultSet rs = stmt.executeQuery(sql);
    

   while (rs.next()) {
    try {
     int c;
     InputStream is = rs.getBinaryStream(3);
     InputStreamReader isr = new InputStreamReader(is,
       "UnicodeLittle");
     String str="";
     while((c=isr.read())!=-1)
     {
      str+=(char)c;      
     }
     System.out.println(str);
     
    } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }

   }
   con.close();
   stmt.close();
   con.close();

  } catch (SQLException ce) {
   System.out.println(ce);
  }
 }

}
 

你可能感兴趣的:(sql,exception,String,jdbc,sqlserver,import)