简体   繁体   中英

i want to connect to SQL Server using Java, please find the code below and i am getting the exception as given below “Error Message”

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");
  }

Error Message:

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM