配置JDBC
时间:2021-07-01 10:21:17
帮助过:8人阅读
com.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBTest {
public static void testConnection(){
//1.加载数据库驱动
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"
);
System.out.println("驱动加载成功!"
);
} catch (ClassNotFoundException e) {
System.out.println("驱动没找到"
);
}
//2.连接数据库
try{
Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=e-commerce", "sa", "sa"
);
if(conn!=
null){
System.out.println("连接成功"
);
}
}catch (SQLException e) {
System.out.println("连接失败"
);
}finally{
//conn.close();
}
}
public static void main(String[] args) {
testConnection();
}
}
配置JDBC
标签:窗口 host 粘贴 connect 属性 箭头 高级 管理 127.0.0.1