当前位置: 首页 > news >正文

怎么做能上谷歌网站吗我想在百度上做广告怎么做

怎么做能上谷歌网站吗,我想在百度上做广告怎么做,南京建设网站哪家好,centos 安装 wordpress【有道云笔记】十二 3.28 JDBC https://note.youdao.com/s/HsgmqRMw 一、JDBC简介 面向接口编程 在JDBC里面Java这个公司只是提供了一套接口Connection、Statement、ResultSet,每个数据库厂商实现了这套接口,例如MySql公司实现了:MySql驱动…

【有道云笔记】十二 3.28 JDBC
https://note.youdao.com/s/HsgmqRMw

一、JDBC简介

面向接口编程

在JDBC里面Java这个公司只是提供了一套接口Connection、Statement、ResultSet,每个数据库厂商实现了这套接口,例如MySql公司实现了:MySql驱动程序里面实现了这套接口,Java程序员只要调用实现了这些方法就可以实现对 MySql数据库的增删改查。

ConnectIon connection= 获得连接;

二、JDBC开发步骤

1、加载驱动Class.forName("");

mysql-connector-j-8.0.31.jar

2、获得连接对象Connection

3、写sql语句

4、创建Statement(一艘船)

5、执行sql语句

(1) 更新类(更改了表里面数据):delete/update/insert executeUpdate()

返回值:int,表示你影响的行数

(2)查询(没有改变表里面数据): select executeQuery()

返回值:结果集ResultSet

6、关闭连接

0

//1、加载驱动Class.forName(""); Class.forName("com.mysql.cj.jdbc.Driver"); //2、获得连接对象Connection Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java230701?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2b8", "root", "1234");

db.properties

JDBCUtil.java

@Test public void test1() { try { //1、加载驱动Class.forName(""); Class.forName("com.mysql.cj.jdbc.Driver"); //2、获得连接对象Connection Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java230701?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2b8", "root", "1234"); //3、写sql语句 String sql = "SELECT id,name,age,gender FROM student"; //4、创建Statement(一艘船) Statement statement = connection.createStatement(); //5、执行sql语句 // (1) 更新类(更改了表里面数据):delete/update/insert executeUpdate() // 返回值:int,表示你影响的行数 // (2)查询(没有改变表里面数据): select executeQuery() // 返回值:结果集ResultSet ResultSet resultSet = statement.executeQuery(sql); List<Student> list = new ArrayList<>(); while (resultSet.next()) {//判断下一个有没有,如果返回true而且指向下一个,没有返回false //每遍历一行,就封装一个学生对象 int id = resultSet.getInt("id"); String name = resultSet.getString("name"); int age = resultSet.getInt("age"); String gender = resultSet.getString("gender"); Student student = new Student(id, name, age, gender); list.add(student); } for (Student student : list) { System.out.println(student); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException throwables) { throwables.printStackTrace(); } finally { //6、关闭连接 } } @Test public void test2() { Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java230701?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2b8", "root", "1234"); String sql = "SELECT id,name,age,gender FROM student"; statement = connection.createStatement(); resultSet = statement.executeQuery(sql); List<Student> list = new ArrayList<>(); while (resultSet.next()) {//判断下一个有没有,如果返回true而且指向下一个,没有返回false int id = resultSet.getInt("id"); String name = resultSet.getString("name"); int age = resultSet.getInt("age"); String gender = resultSet.getString("gender"); Student student = new Student(id, name, age, gender); list.add(student); } for (Student student : list) { System.out.println(student); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException throwables) { throwables.printStackTrace(); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException throwables) { throwables.printStackTrace(); } } if (statement != null) { try { statement.close(); } catch (SQLException throwables) { throwables.printStackTrace(); } } if (connection != null) { try { connection.close(); } catch (SQLException throwables) { throwables.printStackTrace(); } } } } @Test public void testPreparedStatement() { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connection = JDBCUtil.getConnection(); String sql = "SELECT id,name,age,gender FROM student"; //预编译 preparedStatement = connection.prepareStatement(sql); resultSet = preparedStatement.executeQuery(); List<Student> list = new ArrayList<>(); while (resultSet.next()) {//判断下一个有没有,如果返回true而且指向下一个,没有返回false int id = resultSet.getInt("id"); String name = resultSet.getString("name"); int age = resultSet.getInt("age"); String gender = resultSet.getString("gender"); Student student = new Student(id, name, age, gender); list.add(student); } for (Student student : list) { System.out.println(student); } } catch (SQLException throwables) { throwables.printStackTrace(); } finally { JDBCUtil.close(connection, preparedStatement, resultSet); } } @Test public void testInsert() { Connection connection = null; PreparedStatement preparedStatement = null; try { connection = JDBCUtil.getConnection(); //? 占位符 String sql = "insert into student(name,age,gender) values(?,?,?)"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, "张三"); preparedStatement.setInt(2, 23); preparedStatement.setString(3, "女"); System.out.println(preparedStatement); int count = preparedStatement.executeUpdate(); System.out.println("count: " + count); } catch (SQLException throwables) { throwables.printStackTrace(); } finally { JDBCUtil.close(connection, preparedStatement, null); } } @Test public void testDelete() { Connection connection = null; PreparedStatement preparedStatement = null; try { connection = JDBCUtil.getConnection(); String sql = "delete from student where id=?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, 10); System.out.println(preparedStatement); int count = preparedStatement.executeUpdate(); System.out.println("count: " + count); } catch (SQLException throwables) { throwables.printStackTrace(); } finally { JDBCUtil.close(connection, preparedStatement, null); } } @Test public void testUpdate() { Connection connection = null; PreparedStatement preparedStatement = null; try { connection = JDBCUtil.getConnection(); String sql = "update student set name=?,age=?,gender=? where id=?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, "小张"); preparedStatement.setInt(2, 23); preparedStatement.setString(3, "男"); preparedStatement.setInt(4, 9); System.out.println(preparedStatement); int count = preparedStatement.executeUpdate(); System.out.println("count: " + count); } catch (SQLException throwables) { throwables.printStackTrace(); } } @Test public void testLike() { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connection = JDBCUtil.getConnection(); String sql = "select id,name,age,gender from student where name like ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, "%张%"); System.out.println(preparedStatement); resultSet = preparedStatement.executeQuery(); List<Student> list = new ArrayList<>(); while (resultSet.next()) { int id = resultSet.getInt("id"); String name = resultSet.getString("name"); int age = resultSet.getInt("age"); String gender = resultSet.getString("gender"); Student student = new Student(id, name, age, gender); list.add(student); } for (Student student : list) { System.out.println(student); } } catch (SQLException throwables) { throwables.printStackTrace(); } } @Test public void test122() { Connection connection = null; PreparedStatement preparedStatement = null; String sql1 = "UPDATE account SET money=money-1000 WHERE name='张三'"; String sql2 = "UPDATE account SET money=money+1000 WHERE name='李四'"; try { connection = JDBCUtil.getConnection(); // 为false,表示禁用自动提交(默认情况是true) connection.setAutoCommit(false); preparedStatement = connection.prepareStatement(sql1); System.out.println(preparedStatement); preparedStatement.executeUpdate(); // ArithmeticException: / by zero int i = 3 / 0; preparedStatement = connection.prepareStatement(sql2); System.out.println(preparedStatement); preparedStatement.executeUpdate(); // setAutoCommit(false)改成false之后,不会提交数据库,只有调用connection.commit()才提交 connection.commit(); } catch (Exception e) { e.printStackTrace(); try { connection.rollback(); } catch (SQLException throwables) { throwables.printStackTrace(); } } finally { JDBCUtil.close(connection, preparedStatement, null); } }

三、JDBC接口核心的API

|- DriverManager类: 驱动管理器类,用于管理所有注册的驱动程序

|-registerDriver(driver) : 注册驱动类对象

|-Connection getConnection(url,user,password); 获取连接对象

|- Connection接口: 表示java程序和数据库的连接对象。

|- Statement createStatement() : 创建Statement对象

|- PreparedStatement prepareStatement(String sql) 创建PreparedStatement对象

|- CallableStatement prepareCall(String sql) 创建CallableStatement对象(调用写好的存储过程)

|- Statement接口: 用于执行静态的sql语句

|- int executeUpdate(String sql) : 执行静态的更新sql语句

|- ResultSet executeQuery(String sql) :执行的静态的查询sql语句

|-PreparedStatement接口:用于执行预编译sql语句

|- int executeUpdate() : 执行预编译的更新sql语句

|-ResultSet executeQuery() : 执行预编译的查询sql语句

|- ResultSet接口:用于封装查询出来的数据

|- boolean next() : 将光标移动到下一行

|-getXX() : 获取列的值

四、PreparedStatement(预编译)和Statement区别

1、语法不同:

PreparedStatement可以使用预编译的sql,只需要发送一次sql语句,后面只要发送参数即可,公用一个sql语句。

Statement只能使用静态的sql。

delete from student where id=1;

2、效率不同:PreparedStatement使用了sql缓冲区,效率要比Statement高。

3、安全性不同:PreparedStatement可以有效的防止sql注入,而Statement不能防止sql注入。

CREATE TABLE users( id INT PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(10), `password` VARCHAR(10) ); INSERT INTO users(`name`, `password`) VALUES('lisi',123); SELECT * FROM users WHERE 1=1; -- 1=1 true SELECT * FROM users WHERE `name`='lisi' AND `password`='123'; -- zhangsan' OR 1=1 -- y SELECT * FROM users WHERE `name`='zhangsan' OR 1=1 -- y' AND `password`='343';


文章转载自:
http://dinncocontracted.ssfq.cn
http://dinncobandhnu.ssfq.cn
http://dinncohawk.ssfq.cn
http://dinncoaposteriori.ssfq.cn
http://dinncomandora.ssfq.cn
http://dinncoschistoglossia.ssfq.cn
http://dinncodiscrimination.ssfq.cn
http://dinncocannister.ssfq.cn
http://dinncocs.ssfq.cn
http://dinncohaylift.ssfq.cn
http://dinncoantisocialist.ssfq.cn
http://dinncomatsumoto.ssfq.cn
http://dinncogyre.ssfq.cn
http://dinncodownstair.ssfq.cn
http://dinncojulep.ssfq.cn
http://dinncodisaffirmatnie.ssfq.cn
http://dinncoecclesiasticism.ssfq.cn
http://dinncocasemate.ssfq.cn
http://dinncoplaceholder.ssfq.cn
http://dinncovituline.ssfq.cn
http://dinncocheongsam.ssfq.cn
http://dinncolowly.ssfq.cn
http://dinncomachiavelli.ssfq.cn
http://dinncocacm.ssfq.cn
http://dinncobisulfide.ssfq.cn
http://dinncounmistakable.ssfq.cn
http://dinncoacta.ssfq.cn
http://dinncorighthearted.ssfq.cn
http://dinncoacronical.ssfq.cn
http://dinncomagnistor.ssfq.cn
http://dinncoripsonrt.ssfq.cn
http://dinncocollagenolytic.ssfq.cn
http://dinncostubbly.ssfq.cn
http://dinncokike.ssfq.cn
http://dinncorope.ssfq.cn
http://dinncolatheman.ssfq.cn
http://dinncovenerator.ssfq.cn
http://dinncoversitron.ssfq.cn
http://dinncoaglossal.ssfq.cn
http://dinncohaughtiness.ssfq.cn
http://dinncoextra.ssfq.cn
http://dinncoisogeny.ssfq.cn
http://dinncoamentia.ssfq.cn
http://dinncojerk.ssfq.cn
http://dinncofetish.ssfq.cn
http://dinncoprevent.ssfq.cn
http://dinncomammet.ssfq.cn
http://dinncoalsoran.ssfq.cn
http://dinncosomatic.ssfq.cn
http://dinncounderstructure.ssfq.cn
http://dinncobarm.ssfq.cn
http://dinncodemetrius.ssfq.cn
http://dinncosilesia.ssfq.cn
http://dinncophotopolymerization.ssfq.cn
http://dinncomolasse.ssfq.cn
http://dinncooutdoorsman.ssfq.cn
http://dinncoroofage.ssfq.cn
http://dinncopeachful.ssfq.cn
http://dinncoaesir.ssfq.cn
http://dinncomallorca.ssfq.cn
http://dinncosonority.ssfq.cn
http://dinncostovepipe.ssfq.cn
http://dinncoreagument.ssfq.cn
http://dinncooaec.ssfq.cn
http://dinncomycelia.ssfq.cn
http://dinncodecerebrate.ssfq.cn
http://dinncosouthabout.ssfq.cn
http://dinncoremoved.ssfq.cn
http://dinncoantidepressive.ssfq.cn
http://dinncogaza.ssfq.cn
http://dinncovichyssoise.ssfq.cn
http://dinncocomposite.ssfq.cn
http://dinncosward.ssfq.cn
http://dinncoritornello.ssfq.cn
http://dinncogarter.ssfq.cn
http://dinncopentagon.ssfq.cn
http://dinncohypersuspicious.ssfq.cn
http://dinncoherringbone.ssfq.cn
http://dinncobotanica.ssfq.cn
http://dinncounshaved.ssfq.cn
http://dinncoconsular.ssfq.cn
http://dinncoslur.ssfq.cn
http://dinncokikuyu.ssfq.cn
http://dinncohusbandry.ssfq.cn
http://dinncovowellike.ssfq.cn
http://dinncoinconsequent.ssfq.cn
http://dinncopatagonia.ssfq.cn
http://dinncodowncomer.ssfq.cn
http://dinncominimine.ssfq.cn
http://dinncoheteroplasia.ssfq.cn
http://dinncodeflation.ssfq.cn
http://dinnconeuropsychiatry.ssfq.cn
http://dinncopaperless.ssfq.cn
http://dinncopackage.ssfq.cn
http://dinncoroorbach.ssfq.cn
http://dinncodisloyally.ssfq.cn
http://dinncostuddingsail.ssfq.cn
http://dinncoapocalypse.ssfq.cn
http://dinncodivine.ssfq.cn
http://dinncocantrail.ssfq.cn
http://www.dinnco.com/news/120945.html

相关文章:

  • 北京亦庄做网站公司搜索引擎优化的策略主要有
  • 公司网站可以做服务器吗资源
  • 金华建设局政务网站四川省最新疫情情况
  • 成都住建局官网站首页互联网推广公司靠谱吗
  • 企业标识微博搜索引擎优化
  • 企业销售网站建设电商运营公司简介
  • wordpress网站顶部加横幅百度一下首页问问
  • 山西做网站贵吗百度关键词分析工具
  • wordpress中文主题免费下载惠州seo按天计费
  • 外贸网站制作哪家好软文写作的十大技巧
  • 个人做新闻网站网址怎么申请注册
  • 查看wordpress日志文件网站seo收费
  • 网站建设科技公司怎么做电商生意
  • 怎么查网站的浏览量嘉峪关seo
  • 易语言做检测网站更新正规考证培训机构
  • 小企业做网站西安百度推广代理商
  • 重庆网站建设平台湖北网站seo策划
  • 如何用源代码做网站高端建站
  • 百度作文网站科学新概念seo外链平台
  • 织梦可以做微网站吗最有创意的广告语30条
  • 企业做网站的痛点有哪些百度推广效果怎么样
  • 做查工资的网站坚持
  • 章丘网站定制天猫代运营
  • 怎么样用html做asp网站公司运营策划方案
  • 宿迁网站制作公司东莞网站建设
  • 网站优化细节新闻软文发布平台
  • 做好网站怎么做app百度推广怎么运营
  • 免费申请商城网站想学手艺在哪里可以培训
  • 企业网站模板哪个好营销型网站案例
  • html5视频网站模板上海排名优化seo