Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void connectToAndQueryDatabase(String username, String password, String dirPath){
- BufferedWriter bw = null;
- String filePath = "";
- try {
- Class.forName("oracle.jdbc.OracleDriver");
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(WBReader.class.getName()).log(Level.SEVERE, null, ex);
- }
- String url = "jdbc:oracle:thin:@//192.168.1.234:1521/maxrb";
- Connection con = null;
- try {
- con = DriverManager.getConnection(url, username, password);
- } catch (SQLException ex) {
- Logger.getLogger(WBReader.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- Statement stmt = con.createStatement();
- try{
- String qry = "select "
- + "assetnum, wonum, round((actfinish-actstart)*24, 2) duration "
- + "from "
- + "workorder "
- + "where "
- + "status in ('COMP', 'INPRG') "
- + "and istask = '0' "
- + "order by "
- + "assetnum";
- ResultSet rset = stmt.executeQuery(qry);
- String str = "";
- try{
- String fileName = "";
- String file1 = "";
- // int j = 0;
- while (rset.next()){
- file1 = rset.getString(1) + ".txt";
- if (!file1.equals(fileName)){
- // System.out.println(j + ". " + fileName + " : " + file1);
- // j++;
- try{ bw.close();} catch (Exception e){e.toString();}
- fileName = file1;
- filePath = dirPath + "/" + file1;
- File file = new File(filePath);
- try {
- bw = new BufferedWriter(new FileWriter(file, false));
- } catch (IOException ex) {
- Logger.getLogger(WBReader.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- float fl;
- fl = rset.getFloat(3);
- str = fl < 0.0001 ? "" : String.valueOf(fl);
- try {
- // System.out.println("text: " + str);
- if (!str.equalsIgnoreCase("")){
- bw.write(str);
- bw.write("\r\n");
- }
- } catch (IOException ex) {
- Logger.getLogger(WBReader.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- try{ bw.close();} catch (Exception e){e.toString();}
- } finally{
- try { rset.close(); } catch (Exception ignore) {}
- }
- } finally {
- try { stmt.close(); } catch (Exception ignore){}
- }
- } catch (SQLException ex) {
- Logger.getLogger(WBReader.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {con.close();} catch (Exception ignore){}
- }
- }
Add Comment
Please, Sign In to add comment