首页>代码>jsp+servlet仿当当网电商图书系统>/huangdd/src/javafile/DBcon.java
//纯java驱动   使用方法
package javafile;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBcon{
	private Connection con=null;//连接对象,创建执行对象Statement对象
	public DBcon(){
	}
	public Connection getCon(){//获取与对应数据库的连接
		//2,加载驱动
		String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
		//String driver="org.h2.Driver";
		//3,获得连接
		String url="jdbc:sqlserver://localhost:1433;DatabaseName=jspxskaoqin";	
		//String url="jdbc:h2:D:\\JavaEE\\container\\tomcat\\6.0.18.1\\webapps\\eeplat\\WEB-INF\\db\\h2\\config";
		try {
			Class.forName(driver);
			con=DriverManager.getConnection(url,"sa","huang");		
					
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("加载驱动异常");
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("获得连接异常!");
			e.printStackTrace();
		}		
		return con;
	}
	public static void main(String args[]){
		DBcon db=new DBcon();
		Connection con=db.getCon();
		if(con!=null){
		System.out.println("连接成功!");
	
}
	}

}
最近下载更多
 LV6 2023年6月4日
13133117021  LV5 2023年5月21日
cc0706cc  LV4 2023年1月3日
2019188059  LV2 2022年1月9日
枝江tom  LV2 2021年12月25日
无语  LV4 2021年12月10日
zxcvbnmg  LV3 2021年12月8日
wanglinddad  LV55 2021年7月4日
为了水掉6位用户名  LV4 2021年6月28日
 LV5 2021年6月23日
最近浏览更多
taoshen95  LV16 3月26日
ma406805131  LV19 2024年12月18日
我做梦  LV2 2024年12月14日
chinajy  LV2 2024年12月8日
123wwwghh  LV2 2024年9月18日
曾显示  LV6 2024年7月7日
blank_  LV2 2024年6月28日
abcadmin123  LV2 2024年6月23日
tll123456  LV1 2024年6月17日
郭宇航裹裹  LV5 2024年6月9日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友