package com.pub;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnection {
public static Connection getConnction(){
Connection con=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:driver={sql server}; server=.; database=myDatabaseName;user=;pwd=;");
}catch(Exception e){
System.out.println(e.getMessage());
}
return con;
}
public void main(String args[]){
Connection con=DBConnection.getConnction();
if(con!=null){
System.out.println("Connection is successful!!");
}else{
System.out.println("Connection is fail!!");
}
}
}
java不用驱动连接MSSQL数据库
最新推荐文章于 2023-05-11 17:07:26 发布