此程序都是企业级
的数据库开发程序
全面揭示了JAVA对数据库的操作
源代码在线查看: maxrows.java
package results;
import java.sql.*;
import connections.*;
public class MaxRows {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
conn = ConnectionFactory.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery("SELECT * FROM tracks");
int count = 0;
while (rset.next()) {
count++;
}
System.out.println("Unconstrained query returned " + count + " rows");
stmt.setMaxRows(5);
rset = stmt.executeQuery("SELECT * FROM tracks");
count = 0;
while (rset.next()) {
count++;
}
System.out.println("Constrained query returned " + count + " rows");
} catch (Exception e) {
e.printStackTrace();
}
finally {
ConnectionFactory.close(rset);
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
}
}