传统jdbc写法
首页 > 后端开发    作者:StanWind   2016年9月24日 0:57 星期六   热度:2938°   百度已收录  
时间:2016-9-24 0:57   热度:2938° 

package pw.goyd.db;



import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;



import pw.goyd.game.constant.setting.ServerSetting;



/*

 
废弃了 用mybatis代替

  @author StanWind

 


 */

public class DBUtil implements ServerSetting {





// 获取数据库连接

public static Connection getConnection() {

Connection conn = null;

try {

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection("jdbc:mysql://" + M_ADDR + ":"

  • M_PORT + "/" + M_DBNAME, M_ROOT, M_PWD);

    } catch (ClassNotFoundException e) {

    e.printStackTrace();

    } catch (SQLException e) {

    e.printStackTrace();

    }

    return conn;

    }



    // 关闭所有资源

    public static void closeAll(ResultSet rs, Statement stmt, Connection conn) {

    try {

    if (rs != null)

    rs.close();

    if (stmt != null)

    stmt.close();

    if (conn != null)

    conn.close();

    } catch (SQLException e) {

    e.printStackTrace();

    }

    }

    }
二维码加载中...
本文作者:StanWind      文章标题: 传统jdbc写法
本文地址:https://www.stanwind.com/post/12
版权声明:若无注明,本文皆为“Make it Better”原创,转载请保留文章出处。

返回顶部    首页    手机版本    后花园  
版权所有:Make it Better    站长: StanWind    赣ICP备17014296号