读取数据库简单工具类_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 读取数据库简单工具类

读取数据库简单工具类

 2014/6/27 21:32:35  cbcc1990  程序员俱乐部  我要评论(0)
  • 摘要:publicclassDbUtil{privatestaticStringdb_driver="oracle.jdbc.driver.OracleDriver";privatestaticStringdb_url="xx";privatestaticStringdb_userName="xx";privatestaticStringdb_passWord="xx";publicstaticConnectiongetConnection(){Connectionconn=null;try
  • 标签:工具 数据库 数据
class="java" name="code">public class DbUtil {

	private static String db_driver ="oracle.jdbc.driver.OracleDriver";

	private static String db_url = "xx";

	private static String db_userName = "xx";

	private static String db_passWord = "xx";

	public static Connection getConnection() {
		Connection conn = null;

		try {
			Class.forName(db_driver);

			conn = DriverManager.getConnection(db_url, db_userName, db_passWord);

		}
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		catch (SQLException e) {
			e.printStackTrace();
		}

		return conn;
	}

	public static void close(Connection conn, PreparedStatement ps, ResultSet rs) {
		if (rs != null) {
			try {
				rs.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (ps != null) {
			try {
				ps.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (conn != null) {
			try {
				conn.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public static void close(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}

?

发表评论
用户名: 匿名