text operation
package jdbc.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TextManapulate {
public static int writeText() throws SQLException, ClassNotFoundException, FileNotFoundException{
String sql = "insert into tabe_date_text_blob (text) values (?)";
PreparedStatement ps = JdbcMySqlUtil.getInstance().getPrepareStatement(sql);
File file = new File("src/jdbc/test/JdbcMySqlUtil.java");
Reader reader = new BufferedReader(new FileReader(file));
ps.setClob(1, reader, file.length());
int x = ps.executeUpdate();
JdbcMySqlUtil.free(null, ps, ps.getConnection());
return x ;
}
public static void readText() throws SQLException, ClassNotFoundException, IOException{
String sql = "select text from tabe_date_text_blob where id = 2";
Statement st = JdbcMySqlUtil.getInstance().getStatement();
ResultSet rs = st.executeQuery(sql);
Reader result = null ;
while (rs.next())
result = rs.getCharacterStream(1);
File file = new File("src/JdbcMySqlUtil.java");
Writer writer = new BufferedWriter(new FileWriter(file)) ;
char [] buf = new char[1024] ;
for ( int i = 0 ; (i = result.read(buf)) > 0 ;)
writer.write(buf, 0, i);
writer.close() ;
JdbcMySqlUtil.free(rs, st, st.getConnection());
}
}