0
我們的Java程序從postgreSQL中隨機獲取數據。如何解決? 爲了按順序獲取數據應該做些什麼?數據以postgresql的隨機順序返回
我們在我們的postgresql中有一個名爲grocery的表,它具有從0到99的條目.java代碼以隨機順序獲取整個表。
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost/test", "postgres",
"manafara");
connection.setAutoCommit(false);
Statement st = connection.createStatement();
String sql = "Select * from grocery";
ResultSet rs = st.executeQuery(sql);
Statement st1 = connection.createStatement();
ResultSet rs1 = st1.executeQuery("Select COUNT(*) AS TOTAL from grocery");
int n = 0;
while (rs1.next()) {
n = rs1.getInt("TOTAL");
}
System.out.println("Count: " + n);
int a = 0;
Double db[][] = new Double[n][2];
while (rs.next()) {
db[a][0] = (double) rs.getInt(4);
db[a][1] = rs.getDouble(6);
a++;
}
「*但以隨機順序排列*」 - 沒有'order by',因此數據庫可以自由選擇它喜歡的任何順序。關係數據庫中的行不是***排序的。 –
如何連續讀取? – Dhvhshah
非常感謝你! – Dhvhshah