Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Create_CSV {
- private Component frame; {
- try {
- PrintWriter pw= new PrintWriter(new File("D:\\device_1-Table-View.csv"));
- StringBuilder sb=new StringBuilder();
- Connection connection=null;
- dbConnection obj_dbConnection=new dbConnection();
- connection=obj_dbConnection.getConnection();
- ResultSet rs=null;
- String query="select * from device_1";
- PreparedStatement ps=connection.prepareStatement(query);
- rs=ps.executeQuery();
- while(rs.next()){
- sb.append(rs.getString("ID"));
- sb.append(",");
- sb.append(rs.getString("Temperature"));
- sb.append(",");
- sb.append(rs.getString("Time"));
- sb.append(",");
- sb.append("\r\n"); }
- pw.write(sb.toString());
- pw.close();
- System.out.println("finished");
- JOptionPane.showMessageDialog(frame,
- "Your file is saved on D:\\ drive");
- } catch (Exception e) {
- JOptionPane.showMessageDialog(frame,
- "Please try your location to save file",
- "Location error",
- JOptionPane.ERROR_MESSAGE);
- // TODO: handle exception
- } }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement