哪位大神棒棒小菜鸟?
珀耳塞福尼 2018-12-18 11:58:16 用JDBC在处理大文本数据时,具体将一本小说插入到mysql数据库中。我已经确保数据库连接正确,但尝试了很多方法 老是将小说不能成功插入数据库中以下是我实现功能的部分
PreparedStatement pstmt = null;
Connection connection = null;
try {
// a. a. 导入驱动,加载具体的驱动类
Class.forName("com.mysql.jdbc.Driver");// 加载驱动
// b. 与数据库建立连接
connection = DriverManager.getConnection(URL, USERNAME, PWD);
String sql = "insert into mynovel(id,novel) values(?,?) ";
pstmt = connection.prepareStatement(sql); pstmt.setInt(1, 1);
File file = new File("F:\\all.txt");
InputStream in = new FileInputStream(file);
Reader reader = new InputStreamReader(in, "GBK"); pstmt.setCharacterStream(2, reader,(int)file.length());
pstmt.executeUpdate();
不知道那部分出现了问题 纠结了很多天了 ,搜了很多资料 但还是成功不了啊