Question
· Dec 24, 2019

JDBC connection issue

 

I am using the below code in my REST service and it throws the error "java.lang.NoClassDefFoundError: com/intersys/jdbc/CacheDataSource] with root cause
java.lang.ClassNotFoundException: com.intersys.jdbc.CacheDataSource
"

Surprisingly when i am using the same code in a static main method its running perfectly. 

package webapps.services.datamgmt.webapps;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.intersys.jdbc.CacheDataSource;

import webapps.services.datamgmt.CacheQueryUtilities;
import webapps.services.datamgmt.dto.UiTestCaseContainer;
import webapps.services.datamgmt.dto.WebAppContainer;

@Path("cache")
public class CosController {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public WebAppContainer getIt() {
        WebAppContainer jsonContainer = new WebAppContainer();
        jsonContainer.setErrorText("No Error");
        jsonContainer.setStatusCode("200");
        return jsonContainer;
    }

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Path("save")
    public WebAppContainer saveCase(UiTestCaseContainer uiTestCaseContainer) {
        try {
//            CacheQueryUtilities cacheQueryUtility = new CacheQueryUtilities();
//            cacheQueryUtility.InsertUpdateUiTestCase(uiTestCaseContainer);
            
            CacheDataSource cacheDataSource = new CacheDataSource();
            cacheDataSource.setURL("jdbc:Cache://127.0.0.1:1972/ABCDNS");
            cacheDataSource.setUser("USERNAME");
            cacheDataSource.setPassword("PASSWORD");
       
            
            Connection dbconnection = cacheDataSource.getConnection();
            Statement st = dbconnection.createStatement(); 
            ResultSet rs = st.executeQuery("SELECT * FROM Table1");
            while (rs.next()) {
                System.out.println(rs.getString(2)); 
            }
         dbconnection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        WebAppContainer jsonContainer = new WebAppContainer();
        jsonContainer.setErrorText("No Error");
        jsonContainer.setStatusCode("200");
        return jsonContainer;
    }
}

Discussion (2)1
Log in or sign up to continue