Java连接数据库增删改查(15)

2021-04-06 00:35

一些基础的关于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){


Java连接数据库增删改查(15).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2021会计顶岗实习计划(新编版)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: