package com.web.study;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties; public class ConnectionFactory { public static String driver;
public static String dburl;
public static String user;
public static String password; public static final ConnectionFactory factory = new ConnectionFactory();
private Connection conn;
static{
Properties prop = new Properties();
try {
InputStream in = ConnectionFactory.class.getClassLoader().getResourceAsStream("dbconfig.properties");
prop.load(in);
} catch (Exception e) {
System.out.println("=====配置文件读取错误=====");
}
driver = prop.getProperty("driver");
dburl = prop.getProperty("dburl");
user = prop.getProperty("user");
password = prop.getProperty("password");
} private ConnectionFactory() { }
public static ConnectionFactory getInstance() {
return factory;
}
public Connection makeConnection() {
try {
Class.forName(driver);
conn = DriverManager.getConnection(dburl,user,password);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
} } package com.web.study; import java.sql.Connection; public class ConnectionFactoryTest { public static void main(String[] args) throws Exception {
ConnectionFactory cf = ConnectionFactory.getInstance();
Connection conn = cf.makeConnection();
System.out.println(conn.getAutoCommit());
}
}

  

jdbc 配置properties实现的更多相关文章

  1. SpringMVC加载配置Properties文件的几种方式

    最近开发的项目使用了SpringMVC的框架,用下来感觉SpringMVC的代码实现的非常优雅,功能也非常强大, 网上介绍Controller参数绑定.URL映射的文章都很多了,写这篇博客主要总结一下 ...

  2. spring BasicDataSource 数据源配置 sqlserver数据库 oracle数据库 mysql数据jdbc配置

    spring BasicDataSource 数据源配置 sqlserver数据库 oracle数据库 mysql数据jdbc配置 jdbc.properties 文件信息如下: ---------- ...

  3. jdbc配置及使用测试

    源码:https://github.com/xiaostudy/jdbc_test1 这是没有使用连接池的 目录 创建的sql语句create.sql DROP TABLE IF EXISTS t_u ...

  4. jdbc 配置

    jdbc 配置 Class.forName("com.mysql.jdbc.Driver")  ;//加载数据库驱动 Connection conn=null; String ur ...

  5. 六种获取配置properties文件的方法

    总结一下六种获取配置properties文件的方法,代码如下: package com.xujingyang.test ; import java.io.BufferedInputStream ; i ...

  6. Jmeter JDBC配置

    前提条件,驱动包mysql-connector-java-5.1.38-bin.jar要放到本机Java路径:C:\Program Files\Java\jdk1.8.0_73\jre\lib\ext ...

  7. JDBC的MySQL配置properties文件

    参考: http://sgq0085.iteye.com/blog/1262469 e.g. 常用数据库URLDerby:  jdbc:derby://localhost:1527/COREJAVA; ...

  8. Java学习笔记——JDBC读取properties属性文件

    Java 中的 properties 文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件. 文件的内容是格式是"键=值"(key-valu ...

  9. MyBatis XML配置properties

    来源:https://www.w3cschool.cn/mybatis/7zy61ilv.html XML 映射配置文件 MyBatis 的配置文件包含了影响 MyBatis 行为甚深的设置(sett ...

随机推荐

  1. heredoc 和 nowdoc

    heredoc 和 nowdoc     多次使用 php nowdoc HereDoc 插入大量Hmtl都没有成功,一样提示语法有问题,事实上PHP手册注明是这样写的,实在很奇怪 最后发现了问题所在 ...

  2. Examples For PLSQL Cursors - Explicit, Implicit And Ref Cursors

    A cursor acts logically as a pointer into a result set. You can move the cursor through the result s ...

  3. Ubuntu Linux 下文件名乱码(无效的编码)的快速解决办法

    文件是在WIndows 下创建的,Windows 的文件名中文编码默认为GBK,而Linux中默认文件名编码为UTF8,由于编码不一致所以导致了文件名乱码的问题,解决这个问题需要对文件名进行转码.文件 ...

  4. 安全漏洞API接口

    这个是avfisherapi写的API,经常用,每次找他的博客都搜到AV,尴尬..在这里记下来. 0x01 查询最新安全事件和漏洞的接口 接口URL: 乌云网: http://avfisherapi. ...

  5. LINQ 简单用法【1】

    LINQ:Language INtegrated Query,语言集成查询. 以下内容演示如何利用LINQ进行增加,修改,删除和查询操作,针对数据库. 首先创建Linq Class. 添加数据库信息, ...

  6. 现在有T1、T2、T3三个线程,怎样保证T2在T1执行完后执行,T3在T2执行完后执行?使用Join

    public class TestJoin { public static void main(String[] args) { Thread t1 = new Thread(new T1(), &q ...

  7. 可以考虑使用SublimeText编辑器替代notepad++了

    大概是去年吧,这款编辑器神一般的出现在我面前,经过我小心翼翼的试用后发现并不是那么太顺手,插件配置都不太成熟,如Package Control. 最喜欢用它的zencoding还得专门开个小窗:ang ...

  8. C# 创建一个日志文件

    private static string m_fileName = "C:\\ErrorMsg.txt"; public static void CreateErrorLog(s ...

  9. CSS笔记(十二)CSS3之2D和3D转换

    参考:http://www.w3school.com.cn/css3/css3_2dtransform.asp 2D Transform 方法 函数 描述 matrix(n,n,n,n,n,n) 定义 ...

  10. swipejs的bug

    Github:https://github.com/thebird/Swipe 以下bug的修复方式皆来自于网上. 现在最新的版本是2.0,bug如下: 1.触摸后不会自动播放 修复方式, funct ...