Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Getting ClassNotFoundException while connecting with server side SQL database (https://www.askmehelpdesk.com/showthread.php?t=769209)

  • Sep 29, 2013, 04:50 AM
    sushilshingote
    Getting ClassNotFoundException while connecting with server side SQL database
    While connecting with SQL server database which is located at server computer from local computer, I am getting ClassNotFoundException. I wrote following code to connect with SQL server in java:-

    import java.sql.*;

    public class ConnectDatabase {

    Connection dbConnection = null;

    String dbName = "Radiocity_Central";
    String serverip="192.168.69.189";
    String serverport="1433";
    String url = "jdbc:sqlserver://192.168.69.189:1433;instance=MSRS11.MSSQLSERVER;Da tabaseName=Radiocity_Central;integratedSecurity=tr ue";
    String userName = "sa";
    String password = "airwaves";
    final String driverName = "com.microsoft.sqlserver.jdbc.Radiocity_Centra l";
    Statement statement = null;
    ResultSet rs = null;
    int updateQuery = 0;

    public Connection getConnection() {

    System.out.println(url);
    try{
    Class.forName(driverName).newInstance();

    dbConnection = DriverManager.getConnection(url,userName,password) ;
    System.out.println(DriverManager.getDrivers());

    statement = dbConnection.createStatement();

    /*String QueryString = "select Id from openview.dbo.OV_MS_Message where OriginalServiceId like '{FaultDn[1]}'";

    updateQuery = statement.executeUpdate(QueryString);

    if(updateQuery!=0){
    System.out.println("success" + updateQuery);
    }*/
    statement.close();
    dbConnection.close();
    }
    catch (ClassNotFoundException cnfe){
    cnfe.printStackTrace();
    }
    catch (Exception e){
    e.printStackTrace();
    }
    return dbConnection;

    }

    public static void main(String[] args) {

    ConnectDatabase cDB = new ConnectDatabase();
    cDB.getConnection();

    }

    }

    The runtime exception which I am getting is given below:-

    jdbc:sqlserver://192.168.69.189:1433;instance=MSRS11.MSSQLSERVER;Da tabaseName=Ra
    diocity_Central;integratedSecurity=true
    java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.Radiocity_Central

    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at ConnectDatabase.getConnection(ConnectDatabase.java :22)
    at ConnectDatabase.main(ConnectDatabase.java:52)

    Please help me to solve this problem.
  • Dec 2, 2013, 03:15 AM
    Scleros
    Begin by reading How to resolve java.lang.ClassNotFoundException in Java and How to Resolve java.lang.ClassNotFoundException.

  • All times are GMT -7. The time now is 06:16 AM.