欢迎分享,转载请注明来源:内存溢出
1.增加\x0d\x0aString s1="insert into tableNames (id,name,password) values(myseq.nextval,?,?)"\x0d\x0aClass.forName(driver)\x0d\x0aConnection conn = DriverManager.getConnection(url,dbUser,dbPwd)\x0d\x0aPreparedStatement prepStmt = conn.prepareStatement(s1)\x0d\x0aprepStmt.setString(1,name)\x0d\x0aprepStmt.setString(2,password)\x0d\x0aResultSet rs=stmt.executeUpdate()\x0d\x0a2、删除\x0d\x0aString s2="delete from tbNames where name=?"\x0d\x0aClass.forName(driver)\x0d\x0aConnection conn = DriverManager.getConnection(url,dbUser,dbPwd)\x0d\x0aPreparedStatement prepStmt = conn.prepareStatement(s2)\x0d\x0aprepStmt.setString(1,name)\x0d\x0aResultSet rs=stmt.executeUpdate()\x0d\x0a3、修改\x0d\x0aString s3=“update tbNames set name=? where id=?”\x0d\x0aClass.forName(driver)\x0d\x0aConnection conn = DriverManager.getConnection(url,dbUser,dbPwd)\x0d\x0aPreparedStatement prepStmt = conn.prepareStatement(s3)\x0d\x0aprepStmt.setString(1,name)\x0d\x0aprepStmt.setString(2,id)\x0d\x0aResultSet rs=stmt.executeUpdate()\x0d\x0a4、查询\x0d\x0aString s4="select id,name,password from tbNames"\x0d\x0aClass.forName(driver)\x0d\x0aConnection conn = DriverManager.getConnection(url,dbUser,dbPwd)\x0d\x0aStatement stmt=conn.createStatement()\x0d\x0aResultSet rs = stmt.executeQuery(s4)\x0d\x0awhile(rs.next){\x0d\x0aint id=rs.getInt(1)\x0d\x0aString name = rs.getString(2)\x0d\x0aString pwd=rs.getString(3)\x0d\x0aSystem.out.println(id+name+pwd)} \x0d\x0a\x0d\x0a以上四步必须都得关闭连接;!!!\x0d\x0ars.close()\x0d\x0astmt.close()\x0d\x0aconn.close()创扰睁建一个以JDBC连接数缓态岁据库的程序,包含7个步骤: 1、加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这闭含通过java.lang.Class类的静态方法forName(String className)实现。
赞
(0)
打赏
微信扫一扫
支付宝扫一扫
最初级简单欧姆龙plc小程序,题目1 两个按钮任意按一个灯亮,否则灯灭。 题目2 按钮按两次灯亮
上一篇
2023-05-25
苹果手机怎样退出当前页面
下一篇
2023-05-25
评论列表(0条)