1. 程式人生 > >向mysql資料庫中插入大文字

向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();
}