【Java】Java连接Mysql数据库的demo示例

【Java】Java连接Mysql数据库的demo示例


2024年2月19日发(作者:)

try { e(""); //jdbc mysql连接驱动 conn=nection("jdbc:mysql://localhost:3306/java_chap02?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT","root","123"); stmt=Statement(); } catch(SQLException e) { n("SQL语句出错--->"); tackTrace(); } catch(ClassNotFoundException e) { n("没有发现MySQL驱动--->"); tackTrace(); } } public void closeConn() { try { if(rs!=null){();} if(stmt!=null){();} if(conn!=null){();} } catch(SQLException e) { n("关闭连接出现异常--->"); tackTrace(); } }

public static void main(String args[]){ test tem=new test(); String[] message=new String[3]; String stu_id="1"; try { //初始化数据库连接并更改密码 lConnection(); ("*****数据库连接成功*****n"); String sql="select stu_id,stu_name,stu_gender from student where stu_id='"+stu_id+"'";

=eQuery(sql); if(()){ message[0]=ing(1); message[1]=new String(ing(2).getBytes("gb2312")); message[2]=new String(ing(3).getBytes("gb2312")); } onn();//关闭数据库连接 } catch(Exception ea) { tackTrace(); }

for(int i=0;i<3;i++) (message[i]+"n"); }}demo中:数据库名称:java_chap02表名:student


发布者:admin,转转请注明出处:http://www.yc00.com/news/1708347258a1553765.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信