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条)