各种数据库的连接连接connection方法

上传人:xiao****1972 文档编号:84176937 上传时间:2019-03-03 格式:DOC 页数:2 大小:23.50KB
返回 下载 相关 举报
各种数据库的连接连接connection方法_第1页
第1页 / 共2页
各种数据库的连接连接connection方法_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《各种数据库的连接连接connection方法》由会员分享,可在线阅读,更多相关《各种数据库的连接连接connection方法(2页珍藏版)》请在金锄头文库上搜索。

1、package com.jdbc.myConnection;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;public class ConnectionFactory/获取Oracle连接 public static Connection getOracleConnection() Connection con = null; try Class.forName(oracle.jdbc.OracleDriver); String url = jdbc:oracle:th

2、in:localhost:1521:orcl; con = DriverManager.getConnection(url, scott, tiger); catch (Exception e) e.printStackTrace(); return con; /获取SQLServer的test数据库连接 public static Connection getSQLServerConnection() return getMySQLConnection(test); /获取SQLServer 连接 public static Connection getSQLServerConnection

3、(String databaseName) Connection con = null; try Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver); String url = jdbc:microsoft:sqlServer:/localhost:1433;databaseName= + databaseName; con = DriverManager.getConnection(url, sa, sa); catch (Exception e) e.printStackTrace(); return con; /获取My

4、SQL连接 public static Connection getMySQLConnection() return getMySQLConnection(test); public static Connection getMySQLConnection(String databaseName) Connection con = null; try Class.forName(com.mysql.jdbc.Driver); String url = jdbc:mysql:/localhost/ + databaseName; con = DriverManager.getConnection(url, root, root); catch (Exception e) e.printStackTrace(); return con; /关闭连接 public static void close(Connection con) try con.close(); catch (SQLException e) e.printStackTrace();

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号