public static void game_ua() {
Connection conn = null;
PreparedStatement stmt_user = null;
ResultSet rs_user = null;
BufferedReader bufferedreader = null;
String stemp;
try {
bufferedreader = new BufferedReader(new FileReader("c:/test.txt"));
conn = mysql();
String sql_g_add = "insert into T_GAME_UA_SERIES(ua,series_id) values(?,?)";
stmt_user = conn.prepareStatement(sql_g_add);
int i=0;
while ((stemp = bufferedreader.readLine()) != null) {
i++;
System.out.println(i+": "+stemp);
stmt_user.setString(1, stemp);
stmt_user.setInt(2, 1);
//stmt_user.execute();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs_user != null) {
try {
rs_user.close();
rs_user = null;
} catch (SQLException e) {
rs_user = null;
}
}
if (stmt_user != null) {
try {
stmt_user.close();
stmt_user = null;
} catch (SQLException e) {
e.printStackTrace();
stmt_user = null;
}
}
if (conn != null) {
try {
conn.close();
conn = null;
} catch (SQLException e) {
e.printStackTrace();
conn = null;
}
}
}
}
private static Connection mysql(){
final String userName = "mysql";
final String password = "mysql";
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/test";
conn = DriverManager.getConnection(url, userName, password);
} catch (Exception ex) {
ex.printStackTrace();
}
return conn;
}
public static ArrayList readToBuffer(StringBuffer buffer, InputStream is)
throws IOException {
String line; // 用来保存每行读取的内容
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
line = reader.readLine(); // 读取第一行
ArrayList all = new ArrayList();
while (line != null) { // 如果 line 为空说明读完了
buffer.append(line); // 将读到的内容添加到 buffer 中
all.add(line); // set 到 ArrayList 中
// buffer.append("\\n"); // 添加换行符
line = reader.readLine(); // 读取下一行
}
return all;
}
读文件入库
最新推荐文章于 2022-12-28 19:01:22 发布