admin 管理员组

文章数量: 1087139


2024年3月11日发(作者:animation的形容词)

try

{

e(""); //jdbc mysql

连接驱动

conn=nection("jdbc:mysql://localhost:3306/java_chap02?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimez

one=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


本文标签: 连接 数据库 驱动 形容词 语句