Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Terus mendapatkan konten dari database tabel

Temukan jawabannya, gunakan limit, simpan setiap baris limit ke file dan gunakan tanggal untuk setiap file harian....

              if(vardbtype.equals("MYSQL")){
                    Class.forName("com.mysql.jdbc.Driver");
                    System.out.println("----------------------------");
                    int limitrowmysql = 0;
                    LocalDate now = LocalDate.now();
                    Path path = FileSystems.getDefault().getPath("C:\\Users\\NN\\Documents\\Test\\RowMYSQL\\RowIDMYSQL_" + now.format(DateTimeFormatter.ISO_LOCAL_DATE) + ".txt");
                    if (Files.exists(path)) {
                        String latestRowIdFromFile  = Files.lines(path).max((e1, e2) -> {
                        if (((String)e1).isEmpty() || ((String)e2).isEmpty()) {
                            return -1;
                        }
                        return new Long(e1).compareTo(new Long(e2));
                        }).get(); // read latestRowId from file
                        if (latestRowIdFromFile != null && !latestRowIdFromFile.isEmpty()) {
                            limitrowmysql = Integer.valueOf(latestRowIdFromFile);
                        }
                    } else {
                        limitrowmysql = 0;
                    }
                    Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+ vardbserver, vardbuser, vardbpassword);
                    while(true) {
                        Statement stmts = c.createStatement();
                        int countrowmysql = 0;
                        String sql = ("SELECT * FROM "+ vardbname +" LIMIT "+ limitrowmysql +", 18446744073709551615");
                        ResultSet rss = stmts.executeQuery(sql);
                        while(rss.next()) {
                            String  message = rss.getString("MESSAGE");
                            System.out.println("Message = " + message);
                            TextMessage mssg = session.createTextMessage(message);
                            System.out.println("Sent: " + mssg.getText());
                            producer.send(mssg);
                            countrowmysql = countrowmysql + 1;
                        }

                        rss.close();
                        stmts.close();
                        Thread.sleep(batchperiod2);

                        limitrowmysql = limitrowmysql + countrowmysql;
                        Files.write(path, ("\n" + limitrowmysql).getBytes()); // write latestRowId to file
                    }
                }



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana saya bisa memantau aktivitas SQL di Oracle?

  2. Kueri Penghapusan Berjenjang

  3. Bantuan ekspresi Oracle SQL GROUP BY bukan GROUP BY

  4. Sintaks Oracle yang tersisa bergabung dengan tiga atau lebih tabel

  5. Cara membuat diagram hubungan entitas (ER) menggunakan Oracle SQL Developer