import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TextInser {
public static void main(String[] args) throws SQLException, IOException
{
test("张三");
}
public static void test(String name ) throws SQLException, IOException
{
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
// 创建连接
try{
conn = JdbcUtils.getConnection();
File f = new File("E:\\壳.txt");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String sql = "insert into student (name,text) values (?,?)";
ps = conn.prepareStatement(sql);
// 将姓名 放在第一个占位符的位置
ps.setString(1, name);
// 将文本放在第二个占位符的位置
ps.setCharacterStream(2, br,f.length());
int i =ps.executeUpdate();
System.out.println(i);
br.close();
fr.close();
}finally
{
JdbcUtils.release(rs, ps, conn);
}
}
}
————————————————
版权声明:本文为CSDN博主「明明如月学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w605283073/article/details/46572489