JDBC-处理属性为text的大文本问题
2016-10-13 20:14
218 查看
和处理常见属性大致相同,不同点在于大文本的输入借助于java中io流从读取,然后作为参数传递进去。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSet;
/**
* 存入和读取大文本
* @author Neuclil
*
*/
public class ClobText {
/**
* @param args
* @throws SQLException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, SQLException {
// TODO Auto-generated method stub
create();
}
static void create() throws SQLException, FileNotFoundException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtil.getConnection();
String sql = "insert into text values(1 ,?)";
ps = (PreparedStatement) conn.prepareStatement(sql);
<span style="color:#ff0000;"> File file = new File("src/JdbcUtil.java");
Reader reader = new BufferedReader(new FileReader(file));
ps.setCharacterStream(1, reader, (int)file.length());</span>
int count = ps.executeUpdate();
System.out.println(count + " row affected");
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
} finally {
JdbcUtil.free(rs, ps, conn);
}
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSet;
/**
* 存入和读取大文本
* @author Neuclil
*
*/
public class ClobText {
/**
* @param args
* @throws SQLException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, SQLException {
// TODO Auto-generated method stub
create();
}
static void create() throws SQLException, FileNotFoundException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtil.getConnection();
String sql = "insert into text values(1 ,?)";
ps = (PreparedStatement) conn.prepareStatement(sql);
<span style="color:#ff0000;"> File file = new File("src/JdbcUtil.java");
Reader reader = new BufferedReader(new FileReader(file));
ps.setCharacterStream(1, reader, (int)file.length());</span>
int count = ps.executeUpdate();
System.out.println(count + " row affected");
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
} finally {
JdbcUtil.free(rs, ps, conn);
}
}
}
相关文章推荐
- android文本组件textView属性autolink设置为web,显示网址的处理方法
- android TextView多行文本(超过3行)使用ellipsize="end"属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- 文本处理属性:text-indent:-xxxpx;的作用
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- 处理Hibernate中Pojo对象String属性不能映射Sqlserver2005 text类型字段问题 .
- Axure RP Pro - 相关问题 - Text Panel文本部件不支持超链接及迂回处理办法
- 处理Hibernate中Pojo对象String属性不能映射Sqlserver2005 text类型字段问题
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- JFormattedTextField组件的文本选择问题
- 数学之美 系列十八 - 矩阵运算和文本处理中的分类问题
- 困扰我的问题——条件随机场在文本处理中的应用
- 文本内容处理的问题,请教!
- sqlite3 jdbc、c接口、python接口处理中文时遇到的问题及其解决方法
- tabcontrol的alignment属性设置成Left或Right时,tabPage的text内容不能显示的问题
- sql server2005 jdbc解决自动增长列统一处理问题纪实
- Firefox中Textarea的innerText属性不可用问题
- UITextField 中的文本为空,不代表text属性为nil