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

新网站怎么让百度收录微信小程序怎么制作网页

新网站怎么让百度收录,微信小程序怎么制作网页,淘宝页面设计模板,wordpress后台访问卡1、第一个JDBC程序 步骤总结#xff1a; 创建测试数据库加载驱动#xff0c;固定写法连接数据库获得执行SQL的对象statement执行SQL对象去执行SQLresultset获得返回结果集释放连接 import java.sql.*;public class Jdbc {public static void main(String args[]) throws C…1、第一个JDBC程序 步骤总结 创建测试数据库加载驱动固定写法连接数据库获得执行SQL的对象statement执行SQL对象去执行SQLresultset获得返回结果集释放连接 import java.sql.*;public class Jdbc {public static void main(String args[]) throws ClassNotFoundException, SQLException {//1、加载数据库驱动固定写法Class.forName(com.mysql.jdbc.Driver);//2、用户信息和url连接数据库使用//注意mysql8.0或以上必须在url加上serverTimezoneUTC否则会出现时区异常因为8.0加了新特性安全性也增加了/*useUnicodetrue characterEncodingutf8serverTimezoneUTCuseSSLtrue*/String urljdbc:mysql://localhost:3306/school?useUnicodetruecharacterEncodingutf8serverTimezoneUTCuseSSLtrue;String usernameroot;String password123456;//3、连接数据库数据库对象connection代表数据库Connection connection DriverManager.getConnection(url,username,password);//4、执行SQL对象 StatementStatement statementconnection.createStatement();System.out.println(数据库连接成功);//5、执行SQL对象去执行SQL可能存在结果查看返回值String sqlSELECT * FROM student;ResultSet resultSetstatement.executeQuery(sql);//ResultSet是一个结果集通常是一个列表while (resultSet.next()){System.out.println(id:resultSet.getObject(id));System.out.println(name:resultSet.getObject(name));System.out.println(age:resultSet.getObject(age));System.out.println();}//6、释放连接资源connection.close();statement.close();resultSet.close();} } 2、JDBC对象详解 DriverManager //DriverManager.registerDriver(new com.mysql.jdbc.Driver());//1、加载数据库驱动固定写法Class.forName(com.mysql.jdbc.Driver); //connection 代表数据库 //数据库设置自动提交 //事务提交 //事务回滚 connection.rollback(); connection.commit(); connection.setAutoCommit();URL String urljdbc:mysql://localhost:3306/school?useUnicodetruecharacterEncodingutf8serverTimezoneUTCuseSSLtrue; //mysql-3306 //协议主机地址端口号/数据库名参数1参数2参数3 //oracle--1521 //jdbc:oracle:thin:localhost:1521:sidStatement执行SQL对象 String sqlSELECT * FROM student;String findSql;String insertSql;String updateSql;String delSql;ResultSet resultSetstatement.executeQuery(sql);statement.executeQuery(findSql);//执行查询statement.executeUpdate(insertSql);//更新、插入、删除都是用这个statement.execute(delSql);//执行任何SQL//ResultSet是一个结果集通常是一个列表ResultSet查询的结果集封装了我们的所有查询 结果 获得指定的数据类型 resultSet.getObject();//不知道列类型的情况下使用//如果知道列的类型就使用指定的类型resultSet.getString();resultSet.getInt();resultSet.getFloat();resultSet.getDate();resultSet.getObject();遍历指针 resultSet.beforeFirst();//移动到最前面resultSet.afterLast();//移动到最后面resultSet.next();//移动到下一个数据resultSet.previous();//移动到前一行resultSet.absolute(row);//移动到指定行释放资源 //6、释放连接资源connection.close();statement.close();resultSet.close();3、statement对象 jdbc中的statement对象用于向数据库发送SQL语句想完成对数据库的增删改查只需要通过这个对象想数据库发送增删改查语句即可。 Statement对象的executeUpdate方法用于向数据库发送增、删、改的sql语句executeUpdate执行完后将会返回一个整数即增删改语句导致了数据库几行数据发生了变化 Statement.executeQuery方法用于向数据库发送查询语句executeQuery方法返回代表查询结构的ResultSet对象 工具类 package com.test.util;import java.io.InputStream; import java.sql.*; import java.util.Properties;public class JdbcUtils {private static String drivernull;private static String urlnull;private static String usernamenull;private static String passwordnull;static {try {//获取到配置文件流InputStream inputStreamJdbcUtils.class.getClassLoader().getResourceAsStream(db.properties);//用关键字new创建properties对象Properties properties new Properties();//load方法将流加载进properties对象properties.load(inputStream);//调用方法获取相关属性driverproperties.getProperty(driver);urlproperties.getProperty(url);usernameproperties.getProperty(username);passwordproperties.getProperty(password);Class.forName(driver);} catch (Exception e) {e.printStackTrace();}}public static Connection getConnection() throws SQLException {return DriverManager.getConnection(url,username,password);}public static void release(Connection connection, Statement statement, ResultSet resultSet){if (resultSet!null){try {resultSet.close();} catch (SQLException e) {throw new RuntimeException(e);}}if (statement!null){try {statement.close();} catch (SQLException e) {throw new RuntimeException(e);}}if (connection!null){try {connection.close();} catch (SQLException e) {throw new RuntimeException(e);}}} } CRUD操作-insert package com.test.util;import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;import static com.test.util.JdbcUtils.*;public class JdbcInsert {public void insert() {Connection connectionnull;Statement statementnull;ResultSet resultSetnull;try {//1、获取连接connection JdbcUtils.getConnection();} catch (SQLException e) {throw new RuntimeException(e);}//2、获得执行SQL对象try {statement connection.createStatement();String sqlInsertINSERT INTO student(id,name,age) VALUES (6,李白,99);int istatement.executeUpdate(sqlInsert);if (i0){System.out.println(插入成功);}} catch (SQLException e) {throw new RuntimeException(e);}//3、关闭资源release(connection,statement,resultSet);}} CRUD操作-update package com.test.util;import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import static com.test.util.JdbcUtils.release; public class JdbcUpdate {public void update() {Connection connection null;Statement statement null;ResultSet resultSet null;try {connection JdbcUtils.getConnection();} catch (SQLException e) {throw new RuntimeException(e);}try {statementconnection.createStatement();String sqlUpdateUPDATE student SET name杜甫 WHERE id1;int istatement.executeUpdate(sqlUpdate);if (i0){System.out.println(更新成功);}} catch (SQLException e) {throw new RuntimeException(e);}release(connection,statement,resultSet);}}CRUD操作-delete package com.test.util;import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;import static com.test.util.JdbcUtils.release;public class JdbcDel {public void del(){Connection connectionnull;Statement statementnull;ResultSet resultSetnull;//1、调用工具类的方法获取连接try {connectionJdbcUtils.getConnection();} catch (SQLException e) {throw new RuntimeException(e);}try {statementconnection.createStatement();String sqlDelDELETE FROM student WHERE id3;int istatement.executeUpdate(sqlDel);if (i0){System.out.println(删除成功);}} catch (SQLException e) {throw new RuntimeException(e);}release(connection,statement,resultSet);}} CRUD操作-selecet package com.test.util;import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;public class JdbcSelect {public void select(){Connection connectionnull;Statement statementnull;ResultSet resultSetnull;try {connectionJdbcUtils.getConnection();} catch (SQLException e) {throw new RuntimeException(e);}try {statementconnection.createStatement();} catch (SQLException e) {throw new RuntimeException(e);}String sqlSelectSELECT * FROM student;try {resultSetstatement.executeQuery(sqlSelect);while (resultSet.next()){System.out.println(id:resultSet.getObject(id)\t);System.out.println(name:resultSet.getObject(name)\t);System.out.println(age:resultSet.getObject(age)\t);System.out.println();}} catch (SQLException e) {throw new RuntimeException(e);}} } 4、SQL注入问题 sql存在漏洞会被攻击冬至数据泄露SQL会被拼接 or 5、PreparedStatement对象 PreparedStatement可以防止SQL注入效率更高。 package com.test.util;import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import static com.test.util.JdbcUtils.release; public class JdbcPsDel {public void psDel() {Connection connection null;PreparedStatement preparedStatement null;ResultSet resultSetnull;try {connectionJdbcUtils.getConnection();//获得连接String sqlDelDELETE FROM student WHERE id?;//定义预编译SQL参数用代替preparedStatementconnection.prepareStatement(sqlDel);//预编译preparedStatement.setInt(1,3);//手动给参数值int i preparedStatement.executeUpdate();//执行if (i0){System.out.println(删除成功);}} catch (SQLException e) {throw new RuntimeException(e);}release(connection,preparedStatement,resultSet);//释放资源}} 6、JDBC操作事务 要么成功要么失败 ACID原则 原子性要么全部完成要么都不完成 一致性总数不变 隔离性多个进程互不干扰 持久性一旦提交不可逆持久化到数据库 隔离性问题 脏读一个事务读取了另一个没有提交的事务 不可重复读在同一个事务内重复读取表中的数据表数据发生了改变 虚读幻读在一个事务内读取到了别人插入的数据导致前后读出来结果不一致 7、数据库连接池
http://www.yutouwan.com/news/232928/

相关文章:

  • 个人网站有哪些天元建设集团有限公司李华
  • 网站建设 总体思路做电商网站php开发的流程
  • 做搜索网站挣钱微网站建设教程
  • 专业做外贸英文公司网站书店网站模板下载
  • 上海企业网站建设报价wdcp 网站打不开
  • 深圳福田大型商城网站建设wordpress怎样用
  • wordpress清理网站缓存免费小程序模板
  • 电子商务网站建设前期准备保定seo公司
  • 企业站seo价格建筑a证
  • 南京制作网站自己制作网站需要什么
  • wordpress 同学百度seo优化系统
  • 2345浏览器免费网站免费高清屏幕录像
  • 最新网站建设常见问题wordpress添加页头代码
  • 网站开发项目运营经理岗位职责燕子项目网
  • we建站代还软件开发
  • 快速seo整站优化排行做外贸网站那家专业
  • shopify建站教程wordpress重写页面样式
  • 汕头网站建设设计wordpress 大门户
  • 网站建设维护培训班物业公司和开发公司哪个好
  • 治多县网站建设公司wordpress安装详细
  • 做音乐网站需要版权么网站培训方案
  • 网站打开风险怎么解决好康的网站代码
  • 女装网站建设规划书电商网站建设策划
  • 深圳做网站排名哪家专业西安百姓网免费发布信息网招聘
  • wordpress整站模板南宁seo网络优化公司
  • 上海医疗网站建设视频网站如何做营销
  • 张掖市建设规划局网站建设工程公司 网站
  • 网站首页自动下拉广告怎么推广微信公众号
  • 网站专题页做多大尺寸重庆网站推广平台
  • 招标代理网站建设中太建设集团股份有限公司网站