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

做一个动态网站要多少钱搜索引擎优化简称

做一个动态网站要多少钱,搜索引擎优化简称,网络营销推广的模式包括(),怎么做商城网站JDBC(重点) 数据库驱动 程序会通过数据库驱动,和数据库打交道。 sun公司为了简化开发人员对数据库的统一操作,提供了一个Java操作数据库的规范。这个规范由具体的厂商去完成。对应开发人员来说,只需要掌握JDBC接口。 熟悉java.sql与javax.s…

JDBC(重点)

数据库驱动

程序会通过数据库驱动,和数据库打交道。

sun公司为了简化开发人员对数据库的统一操作,提供了一个Java操作数据库的规范。这个规范由具体的厂商去完成。对应开发人员来说,只需要掌握JDBC接口。

熟悉java.sql与javax.sql包,导入一个数据库驱动包

1.在数据库中提前创建users表,准备连接jdbc

2.查询数据库版本,下载对应jar包。

3.将jar包导入项目。

4.导入jar后,需要添加到库里面。如下操作:

5.不需要更改信息,直接点击ok。

6.创建项目,连接数据库

  • 加载驱动
  • 提供用户信息与url
    • 连接地址+ssl连接关闭+字符集为utf-8+时区设置                
  • 连接数据库,DriverManager 
  • 执行SQL对象, Statement对象
  • 使用sql语言执行sql对象
  • 释放连接
//加载驱动Class.forName("com.mysql.cj.jdbc.Driver");//固定写法//用户信息和url,url基本格式如下://连接地址+ssl连接关闭+字符集为utf-8+时区设置String url="jdbc:mysql://localhost:3306/learndb?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";String username="root";String password="123456";//连接成功,会返回数据库对象 Connection代表数据库Connection connection = DriverManager.getConnection(url, username, password);//执行SQL的对象 StatementStatement statement = connection.createStatement();//执行SQL的对象去执行SQl,可能存在结构,查看返回结果String sql="SELECT * from `users`";ResultSet resultSet = statement.executeQuery(sql);//返回的结果集,结果集中封装了我们全部的查询结果while (resultSet.next()){System.out.println("id="+resultSet.getObject("id"));System.out.println("name="+resultSet.getObject("name"));System.out.println("pwd="+resultSet.getObject("password"));System.out.println("email="+resultSet.getObject("email"));System.out.println("birth="+resultSet.getObject("birthday"));}//释放连接resultSet.close();statement.close();connection.close();}

JDBC对象分析

  • DriverManger

//加载驱动:法一:

DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
//法二:

Class.forName("com.mysql.cj.jdbc.Driver");        //固定写法

//connection是数据库

//数据库设置为自动提交、事务提交、事务回滚

connection.rollback();
connection.commit();
connection.setAutoCommit();

  • URL

mysql默认 端口号为3306,url写法:

jdbc://mysql:/主机地址:端口号/数据库名?参数1&参数2¥参数3

String url="jdbc:mysql://localhost:3306/learndb?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";

  • Statement  执行类,执行SQL的对象

//编写SQL

String sql="SELECT * from `users`";

//可执行的方法

statement.executeQuery();        //执行查询,返回一个结果集

statement.execute()        //执行任何SQL

statement.executeUpdate()        //执行更新、插入、删除,返回一个受影响的行数

  • ResultSet查询结果集,封装了所有的查询结果

获得指定的数据类型

resultSet.getObject();        //在不知道列类型的情况下使用

resultSet.getstring();        //如果知道列的类型就使用指定的类
resultSet.getInt();
resultSet.getFloat();
resultSet.getDate();
resultSet.getObject();

  • 遍历、指针

resultSet.beforeFirst();        //移动到最前面
resultSet.afterLast();        //移动到最后面
resultSet.next();                //移动到下一个数据
resultSet.previous();        //移动到前一行
resultSet.absolute();        //移动到指定行

  • 释放资源

resultSet.close();
statement.close();
connection.close();        //耗资源、用完即关

statement对象

jdbc中的statement对象用于向数据库发送SQL语句,想完成对数据库的增删查改,只需要通过这个对象想数据库发送增删改查语句即可。

Statement对象的executeUpdate方法,用于向数据库发送增、删、改的sql语句,executeUpdate执行完后,将回返回一个整数(即增删改语句导致了数据库几行是数据发生了变化)。

Statement.excuteQuery方法用于向数据库发送查询语句,executeQuery方法返回代表查询结果的ResultSet对象。

前提:

在src目录下创建资源文件,在该文件内部填写数据库用户信息与url等资源信息。

创建一个工具类,完成加载驱动、连接数据库、释放资源等作用。

//工具类
public class JdbcUtils {//提升作用域private static String driver=null;private static String url=null;private static String username=null;private static String password=null;static {try{//通过反射获得具体的资源。getResourceAsStream("db.properties")从该文件获得资源//读取信息InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties");Properties properties = new Properties();properties.load(in);//获取具体的资源driver=properties.getProperty("driver");url=properties.getProperty("url");username=properties.getProperty("username");password=properties.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 conn, Statement st, ResultSet rs){if (rs!=null){try {rs.close();} catch (SQLException throwables) {throwables.printStackTrace();}}if (st!=null){try {st.close();} catch (SQLException throwables) {throwables.printStackTrace();}}if (conn!=null){try {conn.close();} catch (SQLException throwables) {throwables.printStackTrace();}}}
}

代码详解

1.获取资源、加载驱动、连接数据库

增删改的方法:都用executeUpdate

插入数据

//插入数据
public class TestInsert {public static void main(String[] args) {//提升作用域Connection conn=null;Statement st=null;ResultSet rs=null;try {conn = JdbcUtils.getConnection();//获取数据库连接st=conn.createStatement();//获取sql的执行对象String sql="insert into `users`(`id`,`name`,`password`,`email`,`birthday`)" +"values(4,'serenity','123456','4563@qq.com','2020-01-01')";int i=st.executeUpdate(sql);//执行sql代码完成更新表,返回的结果为受影响的行数if (i>0){System.out.println("插入成功");}} catch (SQLException throwables) {throwables.printStackTrace();}finally {JdbcUtils.release(conn,st,rs);//调用工具类,释放资源}}
}

插入成功标志:

删除数据:

主要是更改sql代码

//删除数据
public class TestDelete {public static void main(String[] args) {//提升作用域Connection conn=null;Statement st=null;ResultSet rs=null;try {conn = JdbcUtils.getConnection();//获取数据库连接st=conn.createStatement();//获取sql的执行对象String sql="DELETE FROM users where id=4";int i=st.executeUpdate(sql);//执行sql代码完成更新表,返回的结果为受影响的行数if (i>0){System.out.println("删除成功");}} catch (SQLException throwables) {throwables.printStackTrace();}finally {JdbcUtils.release(conn,st,rs);//调用工具类,释放资源}}
}

更改数据

查看数据:利用executeQuery

PrepareStatement对象

PrepareStatement可以防止SQL注入,效率更好。把传递进来的参数当做字符

假设参数中存在转义字符,如引号,会被直接转义。

  • 新增

  • 删除

  • 更新

  • 查询

idea连接数据库

若未成功,可修改版本。

连接上数据库后

选择数据库后,可双击打开数据库表中查看信息。

事务

要么都成功,要么都失败

ACID原则

  • 原子性:要么全部完成,要么都不完成
  • 一致性:总数不变
  • 隔离性:多个进程互不干扰
  • 持久性:一旦提交不可逆,持久化到数据库

隔离性的问题:

脏读:一个事务读取另一个没有提交的事务

不可重复读:在同一个事务内,重复读取表中的数据,表数据发生了改变

虚读(幻读):在一个事务内,读取到了别人插入的数据,导致前后读出来结果不一致

前提:

模拟事务:A给B转账

public class TestTransation01 {public static void main(String[] args) {Connection conn=null;PreparedStatement st=null;ResultSet rs=null;try {//加载驱动conn= JdbcUtils.getConnection();//关闭数据库的自动提交,自动会开启事务conn.setAutoCommit(false);//开启事务//模拟A给B转账String sql1="update account set money=money-100 where name='A'";st=conn.prepareStatement(sql1);st.executeUpdate();String sql2="update account set money=money+100 where name='B'";st=conn.prepareStatement(sql2);st.executeUpdate();//业务完毕,提交事务conn.commit();System.out.println("成功!");} catch (SQLException throwables) {try {conn.rollback();//如果失败则回滚事务} catch (SQLException e) {e.printStackTrace();}throwables.printStackTrace();}finally {//释放资源JdbcUtils.release(conn,st,rs);}}
}

代码解释:

模拟事务A与B转账出现异常:


文章转载自:
http://adultoid.wjrq.cn
http://kedjeree.wjrq.cn
http://person.wjrq.cn
http://saccharined.wjrq.cn
http://negation.wjrq.cn
http://subcrust.wjrq.cn
http://montaria.wjrq.cn
http://teapot.wjrq.cn
http://ephesine.wjrq.cn
http://unoffended.wjrq.cn
http://youthify.wjrq.cn
http://manners.wjrq.cn
http://naevus.wjrq.cn
http://apennine.wjrq.cn
http://stethoscopic.wjrq.cn
http://ruminant.wjrq.cn
http://bastille.wjrq.cn
http://brunet.wjrq.cn
http://upcast.wjrq.cn
http://bardolatry.wjrq.cn
http://coltish.wjrq.cn
http://splodge.wjrq.cn
http://inscape.wjrq.cn
http://deratize.wjrq.cn
http://phytopathogen.wjrq.cn
http://phototelescope.wjrq.cn
http://bazoo.wjrq.cn
http://moonstone.wjrq.cn
http://meagrely.wjrq.cn
http://linctus.wjrq.cn
http://bricklayer.wjrq.cn
http://usurpatory.wjrq.cn
http://subnormal.wjrq.cn
http://asphyxiate.wjrq.cn
http://inflammation.wjrq.cn
http://schatchen.wjrq.cn
http://teaspoon.wjrq.cn
http://goatling.wjrq.cn
http://concernedly.wjrq.cn
http://detestation.wjrq.cn
http://medina.wjrq.cn
http://sudanic.wjrq.cn
http://zamboanga.wjrq.cn
http://zoomorphic.wjrq.cn
http://tolan.wjrq.cn
http://liquorish.wjrq.cn
http://setose.wjrq.cn
http://backwash.wjrq.cn
http://rhovyl.wjrq.cn
http://bullfight.wjrq.cn
http://coaita.wjrq.cn
http://drollery.wjrq.cn
http://fascicled.wjrq.cn
http://yeah.wjrq.cn
http://broadleaf.wjrq.cn
http://slopewash.wjrq.cn
http://microlanguage.wjrq.cn
http://flaxweed.wjrq.cn
http://hangfire.wjrq.cn
http://unemancipated.wjrq.cn
http://salicornia.wjrq.cn
http://crankpin.wjrq.cn
http://euphausid.wjrq.cn
http://congest.wjrq.cn
http://polyandrist.wjrq.cn
http://manicure.wjrq.cn
http://inextenso.wjrq.cn
http://containment.wjrq.cn
http://autoeroticism.wjrq.cn
http://hypocaust.wjrq.cn
http://townee.wjrq.cn
http://keeled.wjrq.cn
http://eucharis.wjrq.cn
http://nonbusiness.wjrq.cn
http://symphilism.wjrq.cn
http://mari.wjrq.cn
http://wandoo.wjrq.cn
http://trinitrobenzene.wjrq.cn
http://undergraduette.wjrq.cn
http://megalopolis.wjrq.cn
http://largesse.wjrq.cn
http://pattypan.wjrq.cn
http://resumable.wjrq.cn
http://maid.wjrq.cn
http://waggonette.wjrq.cn
http://putiphar.wjrq.cn
http://schematise.wjrq.cn
http://arlington.wjrq.cn
http://wiener.wjrq.cn
http://am.wjrq.cn
http://aldermanship.wjrq.cn
http://simpleminded.wjrq.cn
http://transcarbamylase.wjrq.cn
http://evacuate.wjrq.cn
http://paramylum.wjrq.cn
http://karpinskyite.wjrq.cn
http://intrusively.wjrq.cn
http://sizzard.wjrq.cn
http://alderney.wjrq.cn
http://synchroflash.wjrq.cn
http://www.hrbkazy.com/news/87146.html

相关文章:

  • PHP动态网站开发技术试题上海高玩seo
  • 中国最早做网站是谁2022年列入传销组织最新骗法
  • 中小型企业局域网设计方案王通seo
  • 互联网做什么行业前景好北京网站seo服务
  • 新版网站上线十大最免费软件排行榜
  • 免费的黄金网站有哪些霸屏推广
  • 大兴安岭做网站黄冈网站seo
  • 做网站的报价方案seo网络推广企业
  • 宜宾网站建设公司免费推广app平台有哪些
  • 网站招聘栏怎么做大地资源网在线观看免费
  • 音乐APP网站开发app开发成本预算表
  • 平谷网站建设引擎搜索优化
  • jquery网站右侧悬浮返回顶部带双二维码鼠标经过显示全网整合营销推广系统
  • brackets做网站教程58网络推广
  • app wordpress类似网站推广优化设计方案
  • jsp做网站用到的软件上海牛巨仁seo
  • 网站开发的形式百度账号购买网站
  • ui设计公司网站微网站
  • weekly做网站百度seo排名
  • 网站的百度快照如何做自己建网站要花多少钱
  • 专业网站制作推广服务外包网络推广
  • 苏州品牌网站建设网络营销的发展概述
  • 动漫设计是干嘛的百度seo排名报价
  • 外贸上哪个网站开发客户下拉关键词排名
  • 国外网站建设现状图分析地推推广方案
  • 盘锦网站建设价位中国十大网站有哪些
  • gulf oil wordpress太原seo管理
  • 网站建设可行性研究报告十大广告投放平台
  • 网站开发工具的功能如何做市场营销推广
  • wordpress搭建影视站广州网站优化排名系统