在配置环境的时候出现了问题,别人的截图是这样的:
然而我的截图是这样的:
我的相比上面的多出了Modulepath以及Classpath。在同样的eclipse版本以及jar的情况下,别人的可以运行成功,但是我的却出现了如下错误:
以下是代码:
package pkg;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class connect{
public static void main(String [] args) {
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=test";
String userName="sa";//不要写错
String userPwd="114514";//一定不要写错
try { Class.forName(driverName);
System.out.println("加载驱动成功!");
}catch(Exception e){
e.printStackTrace();
System.out.println("加载驱动失败!");
}
try{
Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("连接数据库成功!"); //createStatement()
} catch (SQLException e) { e.printStackTrace();
System.out.print(e.getErrorCode());
System.out.println("数据库连接错误");
System.exit(0);
}
}
}
求大佬解答