Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Export MYSQL rows into several txt files
- try {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Opening connection");
- Connection con = DriverManager.getConnection(
- "jdbc:mysql://localhost/articles", "username", "password");
- String query = "Select title,articletext from articles";
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next()) {
- String title = rs.getString(1);
- String text = rs.getString(2);
- try {
- FileWriter fstream = new FileWriter(title + ".txt");
- BufferedWriter out = new BufferedWriter(fstream);
- out.write(text);
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- System.out.println("Closing connection");
- con.close();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
Add Comment
Please, Sign In to add comment