1 数据库连接、查询、更新 java 、
nameget = '%'+nameget+'%'; 문자열 sqlgname = "gname과 같은 상품에서 선택 *;"; try {pstmt = conn.preparestatement (sqlgname); pStmt.setString (1, nameget); rs = pstmt.executeQuery (); while (rs.next ()) {int gid = rs.getint ( "gid"); 문자열 gname = rs.getString (2); Double GPrice = Rs.getDouble (3); int gnum = rs.getint (4); 상품 상품 = 새로운 상품 (GID, GNAME, GPRICE, GNUM); goodslist.add (상품); }} catch (sqlexception e) {e.printstacktrace (); } 마침내 {dbclose.queryclose (pstmt, rs, conn); }2 、连接数据库
public final class dbconn {public static connection getConn () {Connection conn = null; 문자열 사용자 = "루트"; 문자열 passwd = "루트"; 문자열 URL = "jdbc : mysql : // localhost : 3306/shop"; // 已加载完驱动 try {class.forname ( "com.mysql.jdbc.driver"); conn = drivermanager.getConnection (url, user, passwd); } catch (sqlexception e) {e.printstacktrace (); } catch (classNotFoundException e) {e.printstacktrace (); } return conn; }}这篇文章就介绍到这, 下一篇将为大家更好的更相关的文章。