?? lab7.java
字號:
package day02;
import java.sql.*;
public class Lab7 {
public static void main(String[] args) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = null;
try {
// 取得連接對象
con = JdbcUtil.getConnection();
// 預編譯SQL語句
// sql = "insert into xun " + "values(?,?)";
// ps = con.prepareStatement(sql);
// for (int i = 100; i < 110; i++) {
// // 準備一組參數
// ps.setInt(1, i);
// ps.setString(2, "Rose" + i);
// // 提交參數,數據庫執行相應的操作
// // ps.executeUpdate();
// ps.execute();
// }
JdbcUtil.release(ps);
sql = "select * from xun where studentId >?";
ps = con.prepareStatement(sql);
ps.setInt(1, 10);
// rs = ps.executeQuery();
if (ps.execute()) {
rs = ps.getResultSet();
}
int id = 0;
String name = null;
StringBuffer sb = new StringBuffer();
while (rs.next()) {
id = rs.getInt(1);
name = rs.getString(2);
sb.append("id = " + id);
sb.append(" name = " + name + "\n");
}
System.out.println(sb.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
JdbcUtil.release(rs, ps, con);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -