您好,登錄后才能下訂單哦!
1、java數據庫連接、查詢、更新
nameGet='%'+nameGet+'%'; String sqlGname = "SELECT * FROM GOODS WHERE GNAME LIKE ?"; try { pstmt = conn.prepareStatement(sqlGname); pstmt.setString(1, nameGet); rs = pstmt.executeQuery(); while (rs.next()) { int gid = rs.getInt("gid"); String gname = rs.getString(2); double gprice = rs.getDouble(3); int gnum = rs.getInt(4); Goods goods = new Goods(gid,gname,gprice,gnum); goodsList.add(goods); } } catch (SQLException e) { e.printStackTrace(); }finally { DbClose.queryClose(pstmt, rs, conn); }
2、連接數據庫
public final class DbConn { public static Connection getconn() { Connection conn = null; String user = "root"; String passwd = "root"; String 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; } }
這篇文章就介紹到這,下一篇將為大家更好的更相關的文章。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。