java连不上sql2005,已经导入sqljdbc.jar,求解释啊
packagepkg;importjava.sql.*;publicclassMain{publicstaticvoidmain(String[]args){String...
package pkg;
import java.sql.*;
public class Main{
public static void main(String[] args) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=testzyp11";
String userName = "sa";
String userPwd = "901125";
Connection dbConn =null;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("连接成功!");
}
catch (Exception e)
{
System.out.println("数据库连接失败!");
e.printStackTrace();
}
}
}
报错原因:
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=testzyp11
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at pkg.Main.main(Main.java:15)
数据库连接失败! 展开
import java.sql.*;
public class Main{
public static void main(String[] args) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=testzyp11";
String userName = "sa";
String userPwd = "901125";
Connection dbConn =null;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("连接成功!");
}
catch (Exception e)
{
System.out.println("数据库连接失败!");
e.printStackTrace();
}
}
}
报错原因:
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=testzyp11
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at pkg.Main.main(Main.java:15)
数据库连接失败! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询