请问一下如何用java向mysql数据库的表中添加文本数据?该用的java中的什么方法,最好能举些例子,谢谢!

2024-12-20 22:31:57
推荐回答(1个)
回答1:

//数据库中储存大文本
public static void Rclob() throws Exception{
Connection conn=null;
PreparedStatement ps=null;
try {
conn=DaoUtils.getConnection();
String sql="insert into tiezhi(name,content) value('yang',?)";
ps=conn.prepareStatement(sql);
BufferedReader reader=new BufferedReader( new FileReader(new File("C:\\Users\\光跃\\Desktop\\1.txt")));
ps.setCharacterStream(1, reader,500);
int i=ps.executeUpdate();
System.out.println(i);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DaoUtils.free(null, ps, conn);
}

}