fork download
  1. import java.io.FileOutputStream;
  2. import java.io.OutputStreamWriter;
  3. import java.io.PrintWriter;
  4. import java.sql.DriverManager;
  5. import java.sql.Connection;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8.  
  9. class SelToFile {
  10.  
  11. public static void main(String[] args) throws Exception
  12. {
  13. String url = "jdbc:firebirdsql://host[:port]/<database>";
  14. String username = "user";
  15. String password = "password";
  16. String filename = "result.txt";
  17. String sql = "select F1 from mytable";
  18.  
  19. PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"));
  20. Connection con = DriverManager.getConnection(url, username, password);
  21. Statement stmt = con.createStatement();
  22. ResultSet rs = stmt.executeQuery(sql);
  23. while (rs.next()) out.println(rs.getString(1));
  24. rs.close();
  25. stmt.close();
  26. con.close();
  27. out.close();
  28. }
  29. }
  30.  
Runtime error #stdin #stdout #stderr 0.06s 380224KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.io.FileNotFoundException: result.txt (Permission denied)
	at java.io.FileOutputStream.open(Native Method)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
	at SelToFile.main(Main.java:19)