public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
creatFile(fn, FILE_NAME);
Class.forName("com.mysql.jdbc.Driver");
System.out.println("连接数据库...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println(" 实例化Statement对象...");
stmt = conn.createStatement();
int sunNum = 30;
int pagesize = 0; pagesize = sunNum/2;
for(int i=0;i<=pagesize;i++) {
String sql = "SELECT ID,name, url From websites limit i*2,2;";
ResultSet rs = stmt.executeQuery(sql);
String fn = "F://NEWtest//again4.txt";
wf(fn,"ID,name,url.");
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String url = rs.getString("url");
//String country = rs.getString("country");
//String fourth = rs.getString("fourth");
System.out.print(", FR: " + id);
System.out.print(", SE: " + name);
System.out.print(", TH: " + url);
//System.out.print(", FO: " + country);
System.out.print("\n");
wf(fn,id+ name + url );
}
rs.close();
stmt.close();
conn.close();}
看看我的代码对不,想利用循环分页,目前不知道怎么样把java的变量赋值给sql,帮忙解决一下,写个代码出来吧,我刚学java不到一个星期,谢谢。