向mysql数据库中插入大文本

@Test
public void demo5() throws SQLException, FileNotFoundException{
System.setProperty("jdbc:drivers", "com.mysql.jdbc.Driver");
Properties prop = new Properties();
prop.put("user", "root");
prop.put("password", "321");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/exam",prop);
PreparedStatement prepareStatement = connection.prepareStatement("insert into user (id,username,password,birthday,blog) values (6,'Lily',789,?,?)");
prepareStatement.setDate(1, new java.sql.Date(System.currentTimeMillis()));
//读取一个文本文件
File file = new File("C:\\Users\\Shinelon\\Desktop\\abc.txt");
//创建一个文件流
FileReader fileReader = new FileReader(file);
//转成缓冲流
BufferedReader bufferedReader = new BufferedReader(fileReader);
prepareStatement.setCharacterStream(2, bufferedReader,3000);
prepareStatement.execute();
prepareStatement.close();
connection.close();
}

你可能感兴趣的:(自我总结)