0
String dburl="jdbc:sqlserver://209.18.103.198:1433;CreditDB_V2";
  //Connecting to Database
 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
 Connection con=java.sql.DriverManager.getConnection(dburl,"700User","cred!tUser");
 Thread.sleep(20000);
 if (con!=null)
   {
    System.out.println("Database Connected Successfully");
    Statement stmt=con.createStatement();
    ResultSet rss=stmt.executeQuery("update User_LogDetail set LoginTime=(GETDATE()-   
        35), StatusId = 401 where UserId in(select userid from user_detail where UserName 
        in('sahooxml','gopal','psahoo7'))");
 Thread.sleep(30000);
  while (rss.next()) {
    Object dbtime = rss.getString(1);
    System.out.println(dbtime);
   } //end while
 con.close();
 }
 else
  {
    System.out.println("Database Failed to connect");
  }

错误信息:

Exception in thread "main" java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at Login700.LoginTest(Login700.java:26)
    at Login700.main(Login700.java:242)
4

1 回答 1

3

包含“com.microsoft.sqlserver.jdbc.SQLServerDriver”类的 jar 文件必须在您的类路径中。

于 2012-11-26T08:16:23.733 回答