67,549
社区成员




package connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBAccess {
Connection con=null;
PreparedStatement sta=null;
ResultSet rs=null;
public DBAccess(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException e){
e.printStackTrace();
System.out.println("驱动未找到");
}
}
public void open(){
try{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;databasename=test","topszk","186899");/*数据库名用户名密码我改成我的了*/
if(!con.isClosed()){
System.out.println("连接成功!");//显示是否连接成功
}
}catch(SQLException e){
e.printStackTrace();
System.out.println("数据库未能连接!");
}
}
public static void main(String[] args){
DBAccess dta=new DBAccess();
dta.open();
}
}