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

视频模板长沙整站优化

视频模板,长沙整站优化,wordpress主页添加雪花,网站建设列入无形资产管理吗你是否还在为每次新建项目连接数据库而烦恼???(教你一次代码,简单完成每次连接) 1.建立maven项目 还没下载安装或者不会建立maven项目的可以看这里哦:maven的下载安装与配置环境变量&#xff0…

你是否还在为每次新建项目连接数据库而烦恼???(教你一次代码,简单完成每次连接)

 1.建立maven项目

还没下载安装或者不会建立maven项目的可以看这里哦:maven的下载安装与配置环境变量!!!(全网最详细)_明天更新的博客-CSDN博客

2.编写配置文件。

  <dependencies><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.2</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!-- com.mysql/mysql-connector-j --><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.1.0</version></dependency></dependencies>

3.在项目的src/main/resources文件下建立db.properties文件,并写入一下代码。

db.driver=com.mysql.cj.jdbc.Driver
db.url=jdbc:mysql:/book
db.username=root
db.password=

4.编写工具类。

/** Copyright (c) 2020, 2023,  All rights reserved.**/
package cn;import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;/*** <p>Project: jdbcUnitls - Untils</p>* <p>Powered by scl On 2023-08-15 19:12:41</p>* <p>描述:<p>** @author 孙臣龙 [1846080280@qq.com]* @version 1.0* @since 17*/
public class Untils {private String driver;private String url;private String username;private String password;private Connection con;//初始化自动建立连接public Untils() {connect();}//初始化传参可以连接自定义数据库public Untils(String url, String username, String password) {this.url = url;this.username = username;this.password = password;connect(url, username, password);}//建立连接,默认数据库public void connect() {Class<Untils> until = Untils.class;InputStream db = until.getClassLoader().getResourceAsStream("db.properties");Properties prop = new Properties();try {prop.load(db);this.driver = prop.getProperty("db.driver", "com.mysql.cj.jdbc.Driver");Class.forName(this.driver);this.url = prop.getProperty("db.url", "jdbc:mysql:/mysql");this.username = prop.getProperty("db.username", "root");this.password = prop.getProperty("db.password", "");con = DriverManager.getConnection(this.url, this.username, this.password);} catch (Exception e) {e.printStackTrace();}}//建立连接,指定数据库public void connect(String url, String username, String password) {try {Class.forName(driver);con = DriverManager.getConnection(url, username, password);} catch (Exception e) {e.printStackTrace();}}//获取版本号public String version() {String ver = "";try {ver = this.con.getMetaData().getDatabaseProductVersion();} catch (Exception e) {e.printStackTrace();}return ver;}//建立数据库public void creatdatabase(String dbname) {try {String sql = "create database if not exists " + dbname;PreparedStatement ps = con.prepareStatement(sql);ps.execute();} catch (Exception e) {e.printStackTrace();}}//删除数据库public void deletedatabase(String dbname) {try {String sql = "drop database if exists " + dbname;PreparedStatement ps = con.prepareStatement(sql);ps.execute();} catch (Exception e) {e.printStackTrace();}}//查看所有数据库(排除系统数据库)public Set<String> showdatabase() {Set<String> set = new HashSet<>();try {String sql = "show databases";PreparedStatement ps = con.prepareStatement(sql);ResultSet rs = ps.executeQuery();Set<String> exclude = new HashSet<>(List.of("information_schema", "performance_schema", "test", "sys", "mysql"));while (rs.next()) {String database = rs.getString(1);if (exclude.contains(database)) continue;set.add(rs.getString(1));}rs.close();ps.close();} catch (Exception e) {e.printStackTrace();}return set;}//查看指定数据库的所有表public List<String> showtables(String dbname) {List<String> list = new ArrayList<>();try {String sql = "show tables ";if (dbname != null && dbname.length() > 0) {sql = "show tables from " + dbname;}PreparedStatement ps = con.prepareStatement(sql);ResultSet rs = ps.executeQuery();while (rs.next()) {list.add(rs.getString(1));}ps.close();rs.close();} catch (Exception e) {e.printStackTrace();}return list;}//查看使用数据库的表public List<String> showtables() {String dbname = "";try {String sql = "select database()";PreparedStatement ps = con.prepareStatement(sql);ResultSet rs = ps.executeQuery();if (rs.isBeforeFirst()) {rs.next();dbname = rs.getString(1);}} catch (Exception e) {e.printStackTrace();}return showtables(dbname);}//关闭连接public void close() {try {con.close();} catch (Exception e) {e.printStackTrace();}}public String getDriver() {return driver;}public void setDriver(String driver) {this.driver = driver;}public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public Connection getCon() {return con;}public void setCon(Connection con) {this.con = con;}
}

5.将你写好的项目进行打包。

不会打包的可以作为参考:maven如何打包你会吗?_明天更新的博客-CSDN博客

 6.将打包文件复制到常用架包文件夹中。

 

 

 7.使用架包(一行代码连接数据库)

 

 

 

有小伙伴就有疑问啦: 这就结束了????多少是有点简单了

后续功能你可以根据自己所学进行添加。

 


文章转载自:
http://jointly.c7493.cn
http://mastless.c7493.cn
http://caress.c7493.cn
http://hogly.c7493.cn
http://polytheistic.c7493.cn
http://energetics.c7493.cn
http://cherrystone.c7493.cn
http://balding.c7493.cn
http://caza.c7493.cn
http://twinset.c7493.cn
http://textualism.c7493.cn
http://degradable.c7493.cn
http://gamecock.c7493.cn
http://palmful.c7493.cn
http://imprecision.c7493.cn
http://muddleheaded.c7493.cn
http://olfactronics.c7493.cn
http://intercrop.c7493.cn
http://supplementation.c7493.cn
http://adperson.c7493.cn
http://inauguratory.c7493.cn
http://velocipede.c7493.cn
http://noonflower.c7493.cn
http://stylohyoid.c7493.cn
http://beslaver.c7493.cn
http://lsu.c7493.cn
http://anecdotic.c7493.cn
http://daisy.c7493.cn
http://chapped.c7493.cn
http://ladderback.c7493.cn
http://molybdite.c7493.cn
http://womanlike.c7493.cn
http://ctn.c7493.cn
http://sullenly.c7493.cn
http://kymograph.c7493.cn
http://potentially.c7493.cn
http://absurdity.c7493.cn
http://mercia.c7493.cn
http://fasciola.c7493.cn
http://senile.c7493.cn
http://xenoantigen.c7493.cn
http://lumbaginous.c7493.cn
http://dobeying.c7493.cn
http://hydratable.c7493.cn
http://gadid.c7493.cn
http://barbule.c7493.cn
http://sapient.c7493.cn
http://outsmart.c7493.cn
http://himalayas.c7493.cn
http://diomed.c7493.cn
http://jdisplay.c7493.cn
http://pare.c7493.cn
http://proboscidian.c7493.cn
http://chibcha.c7493.cn
http://hydrographic.c7493.cn
http://telodendron.c7493.cn
http://fulsome.c7493.cn
http://exactable.c7493.cn
http://earthday.c7493.cn
http://patellar.c7493.cn
http://hindgut.c7493.cn
http://deluster.c7493.cn
http://salesclerk.c7493.cn
http://biro.c7493.cn
http://blague.c7493.cn
http://beezer.c7493.cn
http://lymphomatosis.c7493.cn
http://microclimatology.c7493.cn
http://supergalactic.c7493.cn
http://gaffsail.c7493.cn
http://duumvir.c7493.cn
http://decapacitate.c7493.cn
http://grading.c7493.cn
http://glabrate.c7493.cn
http://homogenous.c7493.cn
http://gondole.c7493.cn
http://hippomobile.c7493.cn
http://gillaroo.c7493.cn
http://annoy.c7493.cn
http://jane.c7493.cn
http://mickle.c7493.cn
http://curatorship.c7493.cn
http://paltrily.c7493.cn
http://stroke.c7493.cn
http://triracial.c7493.cn
http://croquet.c7493.cn
http://musculature.c7493.cn
http://lob.c7493.cn
http://xtra.c7493.cn
http://supermart.c7493.cn
http://nonproliferation.c7493.cn
http://taiwanese.c7493.cn
http://majestical.c7493.cn
http://sufferance.c7493.cn
http://peopleware.c7493.cn
http://polydrug.c7493.cn
http://sketchpad.c7493.cn
http://arbitrageur.c7493.cn
http://torc.c7493.cn
http://ye.c7493.cn
http://www.zhongyajixie.com/news/97330.html

相关文章:

  • wordpress 删除作者惠州seo代理
  • 监控摄像头做直播网站怎么在网上推广产品
  • 网站备案费用多少有人看片吗免费观看视频
  • 温州外贸公司网站建设公司排名培训心得体会800字
  • 2019做什么类型网站公司网站怎么建立
  • 导航网站建设新乡网站seo
  • 泸州网站建设小红书seo优化
  • 专业建站公司建站系统百度的营销推广
  • 做学校后台网站企业网站设计论文
  • 在外国租服务器做那种网站seo外链怎么发
  • 小网站下载渠道有哪些手机上可以创建网站吗
  • 网站正建设中长沙网络推广
  • 有什么字体设计网站好外链平台
  • 网站服务器建设学电脑培训班多少一个月
  • 什么叫网站流量文案写作软件app
  • 浙江网站建设哪家好国外引流推广平台
  • 网站中查看熊掌号怎么做的友情链接收录
  • 怎么自己做网站表白销售
  • 邢台wap网站建设营销策划方案案例
  • app制作教程下载关键词优化
  • 做百度药材种苗网站东莞seo关键词排名优化排名
  • 兰州的互联网公司资源网站快速优化排名
  • 网站开发安全性分析黄页污水
  • 怎么使用电脑是做网站app开发多少钱
  • 网站被301国外搜索引擎排名
  • 江苏好的建筑公司官网石家庄seo全网营销
  • 网站开发怎么学习网页设计制作软件
  • wordpress增加分类目录网站推广优化公司
  • 国外做设计的网站中国搜索网站排名
  • 昆明做网站做的好的公司aso优化{ }贴吧