20201104吴东东

一、知识总结
(1)、executeQuery返回值类型是对表的一行
查询的返回值的结果就是结果集,用循环来for知道具体个数;

(2)、 rs.next下一行
while(rs.next() )f

 System. out. println(rs. getObject( "userNAME"));

 System. out . println(rs. get0bject("gender"));

 prepareStatement. close();

 connection. close( );
  查询掉的方法,返回的结果值,

(3)、搭建环境变量
新建一个文件-new-other-web-dynanic web project-shopping-next-next-对号-finish

java resources-src-右键-new-package-com.itlaobing.dbhelper-右键-class-DBHelper

java resources和webcontent中复制HTML中的文件的复制到esp中,及将文件放到javaresource

content-other-jsp-file-index.jsp-finish

    window-最后-server-runtime-add-apache9.0-找目录文件的路径

    -finish-apply and close

    buid path-configur-lib-addlib-server runtime-选中Apache9.0-a

    pply and close

    server-右键-and remove-shopping

    window-preperences-web-jsp files-utf_8-apply and close

    window-preperences-other-utf_8

    再将html改成jspwindow-preperences-server-runtime environm
ents-add-9.0-next-路径-finish-apply and close

package com. laobing. dbh;

import java. sq1. Connection;·

public class DBhelper {

/lmain28l/

public static void main(String[] args) {try {

save();

} catch (Exception e) {

e. printStackTrace();

}

! eaaa2288028kE2 1

public static void save() throws Exception {

1 /019000000100000

C1ass. forName("com. mysq1.jdbc.Driver");

1 120000000890000

Connection connection = DriverManager . getConnection("jdbc :mysql://localhost:3306/db_ _user", "root","");1/300yAsq1900

String sql = "SELECT userNAME , gender FROM t_ user";

1140000391

PreparedStatement prepareStatement = connection. prepareStatement(sql);

1/50000sq1

ResultSet rs=prepareStatement . executeQuery();

ResultSet rs=prepareStatement . executeQuery();

while(rs.next() )f

System. out. println(rs. getObject( "userNAME"));

System. out . println(rs. get0bject("gender"));

prepareStatement. close();

connection. close( );

二、心得体会
老师今天给我们讲了好多数据库内容,环境搭建,收获颇丰,继续加油。

标签

评论

this is is footer