一些基础的关于java jdbc的程序代码
PreparedStatement stmt = null;
String sql = "delete from bbc where name =?";
int x = 0;
try {
stmt = conn.prepareStatement(sql);
stmt.setString(1, key);
x = stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (x == 1) {
return true;
} else {
return false;
}
}
public static boolean modify(Country cou) {
Connection conn = DBConnection.getConnection();
PreparedStatement pstmt = null;
String sql = "update bbc set Region=?,Area=?,Population=?,Gdp=? where name =?";
int x = 0;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, cou.getName());
pstmt.setString(2, cou.getArea());
pstmt.setString(3, cou.getPopulation());
pstmt.setString(4, cou.getGdp());
pstmt.setString(5, cou.getName());
x = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
if(x==1){