TypechoJoeTheme

九肽荷尔蒙's Blog

用户名
密码
用户名
邮箱

九肽荷尔蒙

浅尝辄止,贪得无厌

JDBC笔记(三)

2021-11-01
/
1 评论
/
297 阅读
/
正在检测是否收录...
11/01

JDBC

学习目标
     1. 服务器端分层(web层  service层  dao层)
    2. 封装一个dao层的通用类
    3. 事务
    4. 批处理
    5. 服务器 tomcat
    6. idea中配置tomcat  web项目的创建
    7. 简单介绍servlet    
一、服务器端的三层架构
dao层:与数据库交互
service层:处理业务逻辑
web层:接受请求  做出响应
二、封装一个DAO层的通用类
在BaseDao非静态代码块中创建一个QueryRunner核心对象
创建一个用户增删改的方法
创建一个查询单条记录的方法
创建一个查询多条记录的方法
创建一个查询记录条数的方法
    
package com.offcn.utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;
import java.util.List;

public class BaseDao {
    QueryRunner qr;
    {
        qr = new QueryRunner();
    }
    //新增 删除  修改
    public int update(String sql,Object... params){
        int row = 0;
        try {
            row = qr.update(JDBCUtils.getConnection(), sql, params);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.release();
        }
        return row;
    }
    //查询单条记录
    public <T>T findSingle(String sql,Class<T> clazz,Object... params){
        T t = null;
        try {
            t = qr.query(JDBCUtils.getConnection(),sql,new BeanHandler<>(clazz),params);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.release();
        }
        return t;
    }

    //查询多条记录
    public <T>List<T> findObjs (String sql,Class<T> clazz,Object... params){
        List<T> ts = null;
        try {
            ts = qr.query(JDBCUtils.getConnection(),sql,new BeanListHandler<>(clazz),params);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.release();
        }
        return ts;
    }
    //查询数量
    public int findCount (String sql){
        Long count = 0l;
        try {
            count = (Long)qr.query(JDBCUtils.getConnection(), sql, new ScalarHandler());
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.release();
        }
        return count.intValue();
    }

}
三、事务
conn.setAutoCommit(false) 改为手动提交  开启事务
conn.commit() 提交---try
conn.rollback()-----catch
四、批处理
在连接mysql数据库时设置rewriteBatchedStatements=true参数  开启批处理

addBatch() 预存SQL语句
executeBatch() 执行批处理
clearBatch() 清除预存的SQL语句
五、服务器
服务器: 是一台有CPU、磁盘、内存的机器,给服务器软件提供服务
    
javaWeb项目, 通过客户端或者浏览器可以访问到的网络的程序,该程序需要再服务器软件中运行
    
服务器软件介绍:
    
    Tomcat(Apache) 开源免费使用  使用量最大  java语言开发的
    JBOSS 用量少
    WebLogic(Oracle) 收费
    WebSphere(IBM) 收费

六、Tomcat
1、下载tomcat:https://tomcat.apache.org/
2、直接解压可用  注意 :不宜太深 不能出现中文和空格
Tomcat服务开启:
    bin下的     startup.bat
开启时一闪而退:
    1、JDK的配置配置
        JAVA_HOME           E:\develop\java\jdk.18
        path                %JAVA_HOME%\bin
        CLASSPATH           .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
    2、端口冲突
        修改自己的端口
            conf文件下server.xml中修改port端口
        关闭占用端口的程序
            在dos中使用 netstat -ano找到端口对应程序的pid
            在任务管理器中找到pid对应的程序结束进程
创建一个javaWeb,在tomcat中运行  并访问
    
访问:http://IP:Port/项目访问路径/项目中的其他资源

http://192.168.26.138:8080/offcn/hello.html

Tomcat中  webapps中存放的web项目的结构
    
    项目名
        静态资源
        WEB-INF
            classes 
            lib
            web.xml
七、IDEA中配置tomcat
八、使用HttpWatch截取到请求和响应信息

B/S   C/S区别
    
    
   browser server 浏览器和服务器:小米官网   京东   学生管理系统
    
   client  server   客户端和服务器:英雄联盟  QQ  CTS


静态资源 VS 动态资源




朗读
赞(0)
版权属于:

九肽荷尔蒙's Blog

本文链接:

http://sleeve.top/index.php/archives/163/(转载时请注明本文出处及文章链接)

评论 (1)
  1. vkxseffch 作者
    Windows XP · Internet Explore

    JDBC笔记(三) - 九肽荷尔蒙's Blog
    avkxseffch
    [url=http://www.gno5j028s07e9hr773f7t25qqro39xy6s.org/]uvkxseffch[/url]
    vkxseffch http://www.gno5j028s07e9hr773f7t25qqro39xy6s.org/

    2021-12-17 回复
IP信息

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月

最新回复

  1. fixotaigujup
    2021-12-19

    Urgent imh.mhsz.sleeve.top.vrg.rd intuitively akinetic antiphospholipid [URL=http://damcf.org/drug/sildenafil-vendo/]viagra generique 75 mg[/URL] [URL=http://cocasinclair.com/product/dutas/]retail sale dutas[/URL] [URL=http://graphicatx.com/cialis-in-brazil/]prices of viagra, cialis, lavitra[/URL] [URL=http://nicaragua-magazine.com/item/synthroid/]synthroid online stores[/URL] [URL=http://americanazachary.com/product/lyrica/]lyrica kaufen leipzig[/URL] [URL=http://nicaragua-magazine.com/purchase-kamagra-without-prescription/]generic kamagra 100mg pills[/URL] [URL=http://staffordshirebullterrierhq.com/item/ed-super-advanced-pack/]ed super advanced pack generico online sicuro[/URL] [URL=http://gasmaskedlestat.com/keftab/]buy keftab[/URL] [URL=http://telugustoday.com/product/doxazosin/]buy doxazosin online[/URL] [URL=http://staffordshirebullterrierhq.com/item/jelly-pack-15/]low priced jelly pack 15[/URL] [URL=http://johncavaletto.org/amoxicillin/]amoxicillin[/URL] [URL=http://homemenderinc.com/product/viagra/]acheter du viagra 50 pills[/URL] [URL=http://nutrabeautynutrition.com/pill/cialis-strong-pack-60/]cialis strong pack 60 without pres[/URL] [URL=http://solepost.com/product/prednisone/]prednisone by check[/URL] uncertain arriving viagra advertisement buy dutas online in usa cialis generic synthroid online europe lyrica kaufen leipzig generic kamagra lowest purchase kamagra without prescription ed-super-advanced-pack prescription usa buy keftab generic for doxazosin best generic jelly pack 15 online amoxicillin can you order viagra online cialis-strong-pack-60 en china prednisone by check perimenopausal futile http://damcf.org/drug/sildenafil-vendo/ sildenafil vendo http://cocasinclair.com/product/dutas/ buy dutas online in usa buy dutas online in usa http://graphicatx.com/cialis-in-brazil/ cialis http://nicaragua-magazine.com/item/synthroid/ china synthroid online http://americanazachary.com/product/lyrica/ lyrica http://nicaragua-magazine.com/purchase-kamagra-without-prescription/ kamagra sans ordonnances http://staffordshirebullterrierhq.com/item/ed-super-advanced-pack/ cheap ed super advanced pack without a prescription http://gasmaskedlestat.com/keftab/ buy keftab online http://telugustoday.com/product/doxazosin/ doxazosin tablets http://staffordshirebullterrierhq.com/item/jelly-pack-15/ jelly-pack-15 online canadian http://johncavaletto.org/amoxicillin/ comprar amoxicillin en internet http://homemenderinc.com/product/viagra/ buy viagra online in ireland http://nutrabeautynutrition.com/pill/cialis-strong-pack-60/ buy cialis strong pack 60 w not prescription http://solepost.com/product/prednisone/ prednisone dozirovkamg guaranteed lowest price complexities frustrating ethics.

  2. buying stromecto
    2021-12-19
  3. etufghufeaje
    2021-12-19

    Night wpu.gvif.sleeve.top.yjr.rh relationship; adult magnesium [URL=http://otrmatters.com/item/lowest-cost-propecia/]propecia[/URL] [URL=http://memoiselle.com/product/proscar/]proscar online next day shipping[/URL] [URL=http://thatpizzarecipe.com/amoxil/]amoxil[/URL] [URL=http://anguillacayseniorliving.com/item/prednisone-discount-prices/]40 prednisone from top rated[/URL] [URL=http://johncavaletto.org/drugs/levitra-20mg-achat/]buy generic levitra online with echeck[/URL] [URL=http://washingtonsharedparenting.com/clomid/]clomid panama[/URL] [URL=http://mrcpromotions.com/drug/tretinoin-canada/]buy cheap tretinoin[/URL] [URL=http://anguillacayseniorliving.com/drugs/retin-a/]quebec retin a[/URL] [URL=http://americanazachary.com/product/propecia/]fastest delivery propecia[/URL] [URL=http://celebsize.com/soft-pack-40/]soft-pack-40 online[/URL] [URL=http://americanazachary.com/drugs/xenical/]medicine xenical[/URL] [URL=http://nicaragua-magazine.com/cheap-generic-substitute-doxycycline/]doxycycline[/URL] [URL=http://wow-70.com/pill/cytotec/]buy cytotec online free pills[/URL] [URL=http://damcf.org/drug/diclofenac/]diclofenac come si usa[/URL] fraction lowest cost propecia proscar online next day shipping generic amoxil no perscription prednisone levitra 20mg achat 50 mg clomid online uk tretinoin canada products like retin a real propecia without a prescription soft-pack-40 xenical doxycycline doxycycline online no presciption is buying cytotec from canada safe diclofenac come si usa lubricant adjuvants, intoxicating http://otrmatters.com/item/lowest-cost-propecia/ cheap generic propecia pills http://memoiselle.com/product/proscar/ proscar through mail http://thatpizzarecipe.com/amoxil/ amoxil sites http://anguillacayseniorliving.com/item/prednisone-discount-prices/ prednisone drug company prednisone online order guide http://johncavaletto.org/drugs/levitra-20mg-achat/ levitra uk pharmacy http://washingtonsharedparenting.com/clomid/ buy clomid without prescription http://mrcpromotions.com/drug/tretinoin-canada/ buy tretinoin online canada http://anguillacayseniorliving.com/drugs/retin-a/ retin a http://americanazachary.com/product/propecia/ propecia and mexico other products like propecia http://celebsize.com/soft-pack-40/ soft-pack-40 http://americanazachary.com/drugs/xenical/ xenical http://nicaragua-magazine.com/cheap-generic-substitute-doxycycline/ doxycycline http://wow-70.com/pill/cytotec/ cytotec http://damcf.org/drug/diclofenac/ diclofenac sin receta en farmacias introducing disorientation without.

  4. jonn2
    2021-12-19
  5. jonn1
    2021-12-19