1 、 java 数据库连接、查询、更新
nameget = '%'+nameget+'%'; String sqlgname = "Selecione * de mercadorias onde o gname gosta?"; tente {pstmt = Conn.Preparestatement (sqlgname); Pstmt.SetString (1, Nameget); rs = pstmt.executeQuery (); while (rs.Next ()) {int gid = rs.getInt ("gid"); String gname = rs.getString (2); duplo gprice = rs.getDouble (3); int gnum = rs.getInt (4); Mercadorias = novos bens (GID, GNAME, GPRICE, GNUM); benslist.add (bens); }} catch (sqLexception e) {e.printStackTrace (); } finalmente {dbclose.queryclose (pstmt, rs, conn); }2 、连接数据库
public Final Class DBConn {Public Static Connection getConn () {conexão conn = null; String user = "root"; String passwd = "root"; String url = "jdbc: mysql: // localhost: 3306/shop"; // 已加载完驱动 tente {class.ForName ("com.mysql.jdbc.driver"); Conn = DriverManager.getConnection (URL, Usuário, Passwd); } catch (sqLexception e) {e.printStackTrace (); } catch (classNotFoundException e) {e.printStackTrace (); } retornar Conn; }}这篇文章就介绍到这 , 下一篇将为大家更好的更相关的文章。