/**
 * microsoft的JDBC的连接数据库方式
 */
import java.sql.*;public class Test2 {
static Connection ct = null;
static PreparedStatement ps = null;
static ResultSet rs = null;  public static void main(String[] args){ try {
// 1.加在驱动
Class.forName("com.microsoft.jdbc.sqlServer.SQLServerDriver");
 
// 2.得到连接
    ct = DriverManager.getConnection
     ("jdbc:microsoft:sqlserver://localhost:1433; databaseName=ppp", "sa", "sa");  ps = ct.prepareStatement("select * from TABLE1");
rs = ps.executeQuery();
while (rs.next()) {
int i = rs.getInt(1);
String s1 = rs.getString(2);
String s2 = rs.getString(3);
System.out.println(i + " " + s1 + " " + s2); }
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (ct != null) {
ct.close();
}
} catch (Exception e) {
e.printStackTrace();
}
// TODO: handle exception
} }}
运行提示:java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;databaseName=ppp  找不到合适的驱动是什么问题,连接数据库的三个jar包我都已经导入过工程里面了,用的是sqlserver2000,打过SP4补丁。

解决方案 »

  1.   

    1、首先确定你导入的jar跟你的数据库是否匹配2、看这样改行不行
    // 1.加在驱动
    Class.forName("com.microsoft.sqlServer.jdbc.SQLServerDriver");
      
    // 2.得到连接
    ct = DriverManager.getConnection
    ("jdbc:sqlserver://localhost:1433; databaseName=ppp", "sa", "sa");  3、如果还不行,你在工程上右键 buildpath ->configure build path 在切换到librarys选项卡看看导入驱动jar是否正确。
      

  2.   

    可以的!连接成功了,但是提示我表TABLE1对象名无效。晕倒!
      

  3.   

      终于知道了原因,默认是sa登录的,要去更改sa账户的默认数据库为你要连接的数据库
      

  4.   

      终于知道了原因,默认是sa登录的,要去更改sa账户的默认数据库为你要连接的数据库
      

  5.   

     跟学校有什么关系,我是自学的!
     而且我觉得很eclipse有时候很诡异,我昨天也照上面尝试了不行。今天居然可以
      

  6.   


    最不诡异的就是程序了,有哪一个IDE不是有大堆的设置,这些参数,往往又跟很多原理性的东西有联系,我想如果你更多的弄清楚来龙去脉,就不会说诡异这个词了