Guest User

Untitled

a guest
Feb 5th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. class MysqlCon{
  4.  
  5. public static void main(String args[]){
  6.  
  7. try{
  8.  
  9. Class.forName("com.mysql.jdbc.Driver");
  10. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sonoo","root","root");
  11.  
  12. Statement stmt=con.createStatement();
  13. ResultSet rs=stmt.executeQuery("select * from location where timestamp > 'May 1, 2017 00:00:00' and timestamp < 'May 1, 2017 23:59:59' ");
  14. while(rs.next())
  15. CSVWriter writer = new CSVWriter(new FileWriter("/tmp/data.csv"), '\t');
  16. Boolean includeHeaders = true;
  17. writer.writeAll(rs, includeHeaders);
  18. writer.close();
  19. con.close();
  20. } catch(Exception e){ System.out.println(e);}
  21. }
  22. }
Add Comment
Please, Sign In to add comment