Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. public class Create_CSV {
  2.     private Component frame; {
  3.         try {
  4.             PrintWriter pw= new PrintWriter(new File("D:\\device_1-Table-View.csv"));
  5.             StringBuilder sb=new StringBuilder();
  6.             Connection connection=null;
  7.             dbConnection obj_dbConnection=new dbConnection();
  8.             connection=obj_dbConnection.getConnection();
  9.             ResultSet rs=null;
  10.             String query="select * from device_1";
  11.             PreparedStatement ps=connection.prepareStatement(query);
  12.             rs=ps.executeQuery();
  13.                 while(rs.next()){
  14.                 sb.append(rs.getString("ID"));
  15.                 sb.append(",");
  16.                 sb.append(rs.getString("Temperature"));
  17.                 sb.append(",");
  18.                 sb.append(rs.getString("Time"));
  19.                 sb.append(",");
  20.                 sb.append("\r\n"); }
  21.             pw.write(sb.toString());
  22.             pw.close();
  23.             System.out.println("finished");
  24.             JOptionPane.showMessageDialog(frame,
  25.                     "Your file is saved on D:\\ drive");
  26.         } catch (Exception e) {
  27.             JOptionPane.showMessageDialog(frame,
  28.                     "Please try your location to save file",
  29.                     "Location error",
  30.                     JOptionPane.ERROR_MESSAGE);
  31.             // TODO: handle exception
  32.         } }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement