糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > dds协议java实现_[dds数据库同步软件]java数据库dds工具

dds协议java实现_[dds数据库同步软件]java数据库dds工具

时间:2018-10-06 10:59:31

相关推荐

dds协议java实现_[dds数据库同步软件]java数据库dds工具

?

在里面为了提高代码的复用性可以建立util

例如 Dbutil

{

? ? private final static String stu_url=”jdbc:mysql://127.0.0.1:3306/shujuku1″;

? private final static String stu_root=”root”;? //账户名称

? private final static String stu_password=”root”; //密码

? private static DruidDateSource dds=null;

? ? static{

? ?dds=new DruidDataSource();

? ?dds.setUsername(“root”);

? ?dds.setPassword(“root”);

? ?dds.setUrl(“jdbc:mysql://127.0.0.1:3306/shujuku1”);

? ?dds.setDriverClassName(“com.mysql.jdbc.Driver”);

? ?dds.setInitialSize(5); //示意当连接池初始化后 在池中最少的链接数

? ?dds.setMaxActive(20);

}

public static DataSource getDS() {

? ?return dds;

?}

public static Connection getDBDconn() {

? ?try {

? ? ?return dds.getConnection();

? ?} catch (SQLException e) {

? ? ?e.printStackTrace();

? ?}

? ?return null;

?}

?

?public static Connection getCon() {

? ?

? ?try {

? ? ?Class.forName(“com.mysql.jdbc.Driver”);

? ? ?return DriverManager.getConnection(stu_url,stu_root, stu_password);

? ?}catch(ClassNotFoundException e){

? ? ?e.printStackTrace();

? ?} catch (SQLException e) {

? ? ?e.printStackTrace();

? ?}

? ?return null;

?}

?

?public static void close(Statement sta) {

? ?try {

? ? ?sta.close();

? ?} catch (SQLException e) {

? ? ?e.printStackTrace();

? ?}

?}

?

?public static void close(ResultSet rs,Statement sta,Connection conn) {

? ?try {

? ? ?if(rs !=null) {

? ? ? ?rs.close();

? ? ?}

? ? ?if(sta !=null) {

? ? ? ?sta.close(); ? ? ? ? ?

? ? ?}

? ? ?if(conn !=null)

? ? ?conn.close();

? ?} catch (SQLException e) {

? ? ?e.printStackTrace();

? ?}

?}

?

?

?public static void close(ResultSet rs) {

? ?try {

? ? ?rs.close();

? ?} catch (SQLException e) {

? ? ?e.printStackTrace();

? ?}

?}

?

?

?public static void close(Statement sta,Connection conn) {

? ?try {

? ? ?if(sta !=null) {

? ? ? ?sta.close(); ? ? ? ? ?

? ? ?}

? ? ?if(conn !=null)

? ? ?conn.close();

? ? ?

? ? ?

? ?} catch (SQLException e) {

? ? ?e.printStackTrace();

? ?}

?}

?

?

?public static void close(Connection conn) {

? ?try {

? ? ?if(conn !=null) {

? ? ? ?conn.close();

? ? ?}

? ?}catch(SQLException e) {

? ? ?e.printStackTrace();

? ?}

?}

?

}

工具建立好以后

在挪用的时刻? 直接? QueryRunner qr=new QueryRunner(Dbutil.getDS());

再举行自己想举行的方式继续

?

?

原文链接:/sqlserver-mysql/p/12758465.html

本站声明:网站内容来源于网络,若有侵权,请联系我们,我们将及时处理。

如果觉得《dds协议java实现_[dds数据库同步软件]java数据库dds工具》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。