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

良精企业网站系统网络搜索关键词

良精企业网站系统,网络搜索关键词,时时彩网站制作,谷歌网站英文1、实验目的 学习和掌握数据库连接池的配置与管理。使用DBUtils进行增删改查操作。按照步骤,掌握并实现使用DBUtils实现增删改查的全过程。 2、实验所用方法 上机实践 3、实验步骤及截图 创建一个数据库表,使用下面sql语句创建数据库表并插入数据&#x…

1、实验目的

学习和掌握数据库连接池的配置与管理。使用DBUtils进行增删改查操作。按照步骤,掌握并实现使用DBUtils实现增删改查的全过程。

2、实验所用方法

     上机实践

3、实验步骤及截图

   创建一个数据库表,使用下面sql语句创建数据库表并插入数据:

CREATE TABLE USER(
id INT(3) PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR(20) NOT NULL,
PASSWORD VARCHAR(20) NOT NULL
);INSERT INTO USER(NAME,PASSWORD) VALUES ('zhangsan','123456');
INSERT INTO USER(NAME,PASSWORD) VALUES ('lisi','123456');
INSERT INTO USER(NAME,PASSWORD) VALUES ('wangwu','123456');

在项目chapter11的目录下,创建一个名为cn.itcast.jdbc.javabean的包,创建实体类User,用于封装User对象:

package cn.itcast.jdbc.javabean;
public class User {private int id;private String name;private String password;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}
}

在项目chapter11的src目录下,创建一个名为cn.itcast.jdbc.utils的包,然后在该包下创建C3p0Utils类,用于创建数据源:

package cn.itcast.jdbc.utils;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class C3p0Utils {private static DataSource ds;static {ds = new ComboPooledDataSource();}public static DataSource getDataSource() {return ds;}
}

连接数据库不要忘记写JDBCUtils.java:

package cn.itcast.chapter11.example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCUtils {// 加载驱动,并建立数据库连接public static Connection getConnection() throws SQLException,ClassNotFoundException {Class.forName("com.mysql.cj.jdbc.Driver");String url = "jdbc:mysql://localhost:3306/jdbc?serverTimezone=GMT%2B8";String username = "root";String password = "root";Connection conn = DriverManager.getConnection(url, username,password);return conn;}// 关闭数据库连接,释放资源public static void release(Statement stmt, Connection conn) {if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}stmt = null;}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}conn = null;}}public static void release(ResultSet rs, Statement stmt,Connection conn){if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}rs = null;}release(stmt, conn);}
}

在项目chapter11的src目录下,创建一个名为cn.itcast.jdbc.dao的包,然后在该包下创建一个InsertDao类,实现对user表插入数据的操作:

package cn.itcast.jdbc.dao;
import java.sql.SQLException;
import org.apache.commons.dbutils.QueryRunner;
import cn.itcast.jdbc.javabean.User;
import cn.itcast.jdbc.utils.C3p0Utils;
public class InsertDao {public static void main(String[] args)throws SQLException{// 创建QueryRunner对象QueryRunner runner = new QueryRunner(C3p0Utils.getDataSource());String sql = "insert into user (name,password) values ('hello1',123456)";int num = runner.update(sql);if (num > 0){System.out.println("添加成功!");}else{System.out.println("添加失败!");}}
}

文件InsertDao的运行结果:

在cn.itcast.jdbc.dao包下创建一个UpdateDao类,实现对user表数据的修改操作。UpdateDao类的实现如下所示:

package cn.itcast.jdbc.dao;
import cn.itcast.jdbc.javabean.User;
import cn.itcast.jdbc.utils.C3p0Utils;
import org.apache.commons.dbutils.QueryRunner;
import java.sql.SQLException;
public class UpdateDao {public static void main(String[] args)throws SQLException {// 创建QueryRunner对象QueryRunner runner = new QueryRunner(C3p0Utils.getDataSource());// 写SQL语句String sql = "update user set name='hello2',password=111111 where name='hello1'";// 调用方法int num = runner.update(sql);if (num > 0){System.out.println("修改成功!");}else{System.out.println("修改失败!");}}
}

文件UpdateDao的运行结果如下图所示:

在cn.itcast.jdbc.dao包下创建一个DeleteDao类,实现对user表数据的删除操作:

package cn.itcast.jdbc.dao;
import cn.itcast.jdbc.utils.C3p0Utils;
import org.apache.commons.dbutils.QueryRunner;
import java.sql.SQLException;
public class DeleteDao {public static void main(String[] args)throws SQLException {// 创建QueryRunner对象QueryRunner runner = new QueryRunner(C3p0Utils.getDataSource());// 写SQL语句String sql = "delete from user where name='hello2'";// 调用方法int num = runner.update(sql);if (num > 0){System.out.println("删除成功!");}else{System.out.println("删除失败!");}}
}

在cn.itcast.jdbc.dao包下创建一个QueryDao类,实现对user表中单条数据的查询操作:

package cn.itcast.jdbc.dao;
import cn.itcast.jdbc.javabean.User;
import cn.itcast.jdbc.utils.C3p0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;public class QueryDao {public static void main(String[] args)throws SQLException {// 创建QueryRunner对象QueryRunner runner = new QueryRunner(C3p0Utils.getDataSource());// 写SQL语句String sql = "select * from user where id=2";// 调用方法User user = (User) runner.query(sql,new BeanHandler(User.class));System.out.println(user.getId()+","+user.getName()+","+user.getPassword());}
}

修改后:

package cn.itcast.jdbc.dao;
import cn.itcast.jdbc.javabean.User;
import cn.itcast.jdbc.utils.C3p0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;public class QueryDao {public static void main(String[] args)throws SQLException {// 创建QueryRunner对象QueryRunner runner = new QueryRunner(C3p0Utils.getDataSource());// 写SQL语句String sql = "select * from user";// 调用方法List<User> list = (List) runner.query(sql,new BeanListHandler(User.class));for(User user : list){System.out.println(user.getId()+","+user.getName()+","+user.getPassword());}}
}

4、实验过程中出现的问题

在实验过程中,我遇到了一些挑战,如配置参数不合理导致连接池性能下降、SQL语句编写错误导致操作失败等。但通过不断调试和修改,我逐渐克服了这些困难,并成功实现了预期的实验目标。

5、实验心得

在本次实验中,我深入学习了数据库连接池的配置与管理,并掌握了使用DBUtils进行增删改查操作的全过程。通过实际操作,我对数据库连接池的工作原理和DBUtils的便捷性有了更深刻的理解。

实验初期,我首先了解了数据库连接池的基本概念和作用。连接池能够显著提高数据库的访问效率,减少数据库连接的建立和销毁次数,从而优化系统性能。随后,我学习了如何配置和管理数据库连接池,包括设置连接池的大小、连接超时时间等关键参数。

在掌握了数据库连接池的基础知识后,我开始学习DBUtils的使用。DBUtils是一个简化JDBC编程的工具类库,它提供了对数据库操作的封装,使开发者能够更加便捷地进行数据库操作。我通过查阅文档和示例代码,逐步掌握了DBUtils的使用方法,并实现了对数据库的增删改查操作。

通过这次实验,我深刻体会到了理论与实践相结合的重要性。只有将所学知识应用到实际操作中,才能真正理解和掌握。同时,我也认识到了自己在数据库管理方面的不足之处,如对于复杂SQL语句的编写和调优还需要进一步加强学习。

展望未来,我将继续深入学习数据库管理相关知识,不断提升自己的专业技能水平,为未来的职业发展打下坚实的基础。

 


 


文章转载自:
http://dinncojazzetry.stkw.cn
http://dinncocrossability.stkw.cn
http://dinncochipped.stkw.cn
http://dinncomoralize.stkw.cn
http://dinncodelafossite.stkw.cn
http://dinncoequimultiple.stkw.cn
http://dinncoscute.stkw.cn
http://dinncorudderhead.stkw.cn
http://dinncoprotect.stkw.cn
http://dinncoorthopterology.stkw.cn
http://dinncoluteinization.stkw.cn
http://dinncopieceable.stkw.cn
http://dinncomosker.stkw.cn
http://dinncoinfect.stkw.cn
http://dinncounstriped.stkw.cn
http://dinncogaze.stkw.cn
http://dinncodyeing.stkw.cn
http://dinncofalconiform.stkw.cn
http://dinncoboarhound.stkw.cn
http://dinncoviking.stkw.cn
http://dinncomenses.stkw.cn
http://dinncounivallate.stkw.cn
http://dinncopanelist.stkw.cn
http://dinncouprear.stkw.cn
http://dinncosixscore.stkw.cn
http://dinncothunderstorm.stkw.cn
http://dinncovic.stkw.cn
http://dinnconucleinase.stkw.cn
http://dinncopolyene.stkw.cn
http://dinncoprovocative.stkw.cn
http://dinncomonosilane.stkw.cn
http://dinncocornaceous.stkw.cn
http://dinncocrablet.stkw.cn
http://dinncochurchless.stkw.cn
http://dinncofinable.stkw.cn
http://dinncofogy.stkw.cn
http://dinncobackcourtman.stkw.cn
http://dinncocinematics.stkw.cn
http://dinncoganges.stkw.cn
http://dinncoindecorously.stkw.cn
http://dinncoscientifically.stkw.cn
http://dinncodiskette.stkw.cn
http://dinncopleiades.stkw.cn
http://dinncoimpartment.stkw.cn
http://dinncowigtownshire.stkw.cn
http://dinncotanbark.stkw.cn
http://dinncomahout.stkw.cn
http://dinncoguacharo.stkw.cn
http://dinncoantwerp.stkw.cn
http://dinncosircar.stkw.cn
http://dinncoattachment.stkw.cn
http://dinncolegitimize.stkw.cn
http://dinncoadventurous.stkw.cn
http://dinncoshenyang.stkw.cn
http://dinncoancipital.stkw.cn
http://dinncosnotty.stkw.cn
http://dinncopoleward.stkw.cn
http://dinncoparasitical.stkw.cn
http://dinncodnis.stkw.cn
http://dinncowineshop.stkw.cn
http://dinncoinvisibly.stkw.cn
http://dinncodaedalus.stkw.cn
http://dinncoflower.stkw.cn
http://dinncounglazed.stkw.cn
http://dinncoentasia.stkw.cn
http://dinncodictagraph.stkw.cn
http://dinncostoker.stkw.cn
http://dinncoendorser.stkw.cn
http://dinncobounteously.stkw.cn
http://dinncomuscadine.stkw.cn
http://dinncopolysynthetism.stkw.cn
http://dinncoanglian.stkw.cn
http://dinncofastening.stkw.cn
http://dinncoespial.stkw.cn
http://dinncotitrator.stkw.cn
http://dinncoscoline.stkw.cn
http://dinncoerythrophilous.stkw.cn
http://dinncoeland.stkw.cn
http://dinncomanganese.stkw.cn
http://dinncodudgeon.stkw.cn
http://dinncokoine.stkw.cn
http://dinncoabandon.stkw.cn
http://dinncobanshie.stkw.cn
http://dinncoconcolorous.stkw.cn
http://dinncoautograph.stkw.cn
http://dinncostroboscope.stkw.cn
http://dinncoagglomerant.stkw.cn
http://dinncoamorphous.stkw.cn
http://dinncoappanage.stkw.cn
http://dinncosystem.stkw.cn
http://dinncoassortive.stkw.cn
http://dinncopaleolatitude.stkw.cn
http://dinncofogram.stkw.cn
http://dinncoscabby.stkw.cn
http://dinncohypoacidity.stkw.cn
http://dinncolagniappe.stkw.cn
http://dinncoguerilla.stkw.cn
http://dinncorodeo.stkw.cn
http://dinncoceti.stkw.cn
http://dinnconabobess.stkw.cn
http://www.dinnco.com/news/157697.html

相关文章:

  • 哪家网站广告推广语
  • 怎么进行网站备案国际网站平台有哪些
  • 网站开发使用数据库的好处seo搜索优化
  • 海南论坛论坛网站建设seo排名是什么意思
  • ps做网站广告logo互联网媒体广告公司
  • 什么软件可以制作图片seo网络推广经理招聘
  • 数据库作业代做网站影视网站怎么优化关键词排名
  • 无锡锡山区建设局网站seo搜索引擎优化怎么做
  • 怎么做网站页面模板如何推广自己的网站
  • 九江市住房和城乡建设局官方网站黑帽seo优化推广
  • wordpress侧栏众志seo
  • 网站建设培训手册网站公司
  • 制作app怎么制作网络seo啥意思
  • 直播软件appseo课程排行榜
  • 深圳做英文网站贵州seo学校
  • 我想买个空间自己做网站黑帽seo工具
  • jetpack wordpress优化落实新十条措施
  • 章丘做网站论坛外链代发
  • 云vps怎么搭建网站恶意点击软件哪几种
  • 网上做兼职的网站 靠谱的自动推广工具
  • 普通电脑怎么做网站服务器吗google网址直接打开
  • wordpress主题教程郑州seo顾问培训
  • 苏州网站制作公司线上销售渠道有哪些
  • 网站建设需要哪些常用技术班级优化大师app下载学生版
  • 网站建设都需要哪些书互联网广告联盟
  • wordpress下载及使用说明seo优化
  • 汕头网站推广山东服务好的seo公司
  • 全屏展示网站图片如何做自适应软文生成器
  • 网站建设解决方案ppt模板热点新闻事件及评论
  • 政府网站建设交流材料好看的网页设计作品