中国矿业大学web技术实验报告 - 图文 联系客服

发布时间 : 星期四 文章中国矿业大学web技术实验报告 - 图文更新完毕开始阅读dbc3e0250640be1e650e52ea551810a6f524c8bb

《Web技术》实验报告

}

}

stmt = dbc.getConnection().createStatement(); stmt.execute(sql1); stmt.execute(sql2); stmt.execute(sql3); stmt.execute(sql4); stmt.execute(sql5); stmt.close(); dbc.close();

// TODO Auto-generated catch block e.printStackTrace();

} catch (SQLException e) {

在这里是对用户的相关信息进行修改,一共有五条信息,所以需要五条sql语句,并通过用户名来检索到相关的记录并使用Statement对象的execute(String sql)方法来进行删除数据,删除后关闭Statement对象和数据库连接即可。

④查询数据库的表格中的数据的方法。

在这里是对user_information表进行操作。

public String[] queryinformation(String username){

String sql = \+\DataBaseConnection dbc=null; dbc=new DataBaseConnection(); Statement stmt = null; String information[]=null; String nicheng=\; String age=\; String email=\; String aihaonumber=\; String sex=\; String aihao=\; try {

stmt = dbc.getConnection().createStatement(); ResultSet rs=stmt.executeQuery(sql); rs.next();

nicheng=rs.getString(\); age=rs.getString(\); email=rs.getString(\); aihaonumber=rs.getString(\); sex=rs.getString(\); case '0':aihao=\无\

46

name='\+username+\;

/* switch(aihaonumber.charAt(0)){

《Web技术》实验报告

}

}

case '1':aihao=\看电影\ case '2':aihao=\聊天\

case '3':aihao=\看电影、聊天\ case '4':aihao=\唱歌\

case '5':aihao=\看电影、唱歌\ case '6':aihao=\聊天、唱歌\

case '7':aihao=\看电影、聊天、唱歌\ }

if(sex.equals(\ {

sex=\女\

}else sex=\男\

information=new String[]{nicheng,age,sex,email,aihaonumber };

rs.close(); stmt.close(); dbc.close();

// TODO Auto-generated catch block e.printStackTrace();

} catch (SQLException e) {

returninformation;

在这里用一个String数组来接收查询到的信息,首先定义一个sql语句,并根据相关的用户名进行检索,用结果集ResultSet对象来接收查询结果,利用ResultSet对象的get方法根据表头来得到相关的信息存储在String数组中返回即可,最后关闭结果集、Statement对象、数据库的连接。

⑤计算数据库中的表格的中的条目的数量的方法。 这里是对user表进行查询的操作。

publicint query(){

String sql=\; DataBaseConnection dbc=null; dbc=new DataBaseConnection(); Statement stmt = null; introwCount=0; try {

stmt = dbc.getConnection().createStatement(); ResultSet rs=stmt.executeQuery(sql); rs.last();

rowCount=rs.getRow(); rs.close();

47