无法从我的java类调用过程

时间:2016-01-07 07:24:55

标签: java angularjs stored-procedures jdbc

我试图从我的java类中调用存储过程,方法是从angularJs获取输入并将其传递给存储过程,但是它显示错误:javax.naming.NameNotFoundException:jdbc / Oracle - service jboss.naming.context.java。 jdbc.Oracle.Please帮助

java代码

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.log4j.Logger;
import com.att.cbe.common.DBConnection;

@Path("/IntakeFormSection")
public class SampleService {

private static final Logger logger = Logger.getLogger(SampleService.class);

@POST
@Path("/print")
@Produces(MediaType.APPLICATION_JSON)
public String postSomeString(String id) {

    if (logger.isDebugEnabled()) {
        logger.debug("Start postSomething");

    }

    String response = null;
    System.out.println("my firstname is"+id);
    try {

        if (logger.isDebugEnabled())
            logger.debug("in version 1");

        System.out.println("my firstname is" + id);

        Connection conn = DBConnection.getConnection();

        CallableStatement call = conn.prepareCall("{? = call CAMUNDA.get_notification_for_user(?)}");
        System.out.println("++");
        call.setString(1, id);
        call.executeQuery();
        ResultSet rs = (ResultSet) call.getObject(1);
        System.out.println("my firstname is" + rs.getString(0));
        System.out.println("my firstname is" + id);
        response = id;
        call.close();
        conn.close();
    }
    catch (Exception e) {
        response = e.getMessage().toString();
    }

    if (logger.isDebugEnabled()) {
        logger.debug("result: '" + response + "'");
        logger.debug("End postSomething");
    }
    return response;
}
}

AngularJs代码                           在此处插入标题

<script src="lib/js/angular.min.js"></script>
<script src="lib/js/angular-route.min.js"></script>
<script src="lib/js/angular-ui-router.min.js"></script>
</head>
<body ng-controller="post_ctrl">

<script type="text/javascript">
var myapp=angular.module('myapp',[])
myapp.controller('post_ctrl',function($scope,$http){

$scope.fun=function(){
$scope.data=$scope.firstname;
$scope.jsonObj = angular.toJson($scope.data, false);
var response =          $http.post('http://localhost:8080/..../rs/IntakeFormSection/print',    $scope.jsonObj);

};});
</script>


<input type="text" name="firstname" ng-model="firstname"><br>
 <button ng-click="fun()">input</button>



</body>
</html>

DBConnection.java

public class DBConnection {

private static Connection conn = null;
private static DataSource ds = null;

@SuppressWarnings("finally")
public static Connection getConnection() {

    System.out.println("Data connection......");
    try {
        InitialContext ctx = new InitialContext();
        ds = (DataSource) ctx
                .lookup("java:/jdbc/Oracle");
        conn = ds.getConnection();
        System.out.println("connection object:"+conn);
        return conn;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return conn;
    }
}

}

错误:

  12:34:25,072 INFO  [stdout] (http-localhost/127.0.0.1:8080-1) Data      connection......

 12:34:25,086 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) javax.naming.NameNotFoundException: jdbc/Oracle -- service jboss.naming.context.java.jdbc.Oracle

 12:34:25,087 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)

 12:34:25,091 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)

 12:34:25,091 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:120)

 12:34:25,092 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)

 12:34:25,092 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)

 12:34:25,092 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at javax.naming.InitialContext.lookup(InitialContext.java:411)

 12:34:25,092 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at com.att.cbe.common.DBConnection.getConnection(DBConnection.java:19)

 12:34:25,092 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at com.att.cbe.service.SampleService.postSomeString(SampleService.java:48)

 12:34:25,093 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

12:34:25,093 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

12:34:25,093 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

12:34:25,093 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at java.lang.reflect.Method.invoke(Method.java:606)

12:34:25,093 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)

12:34:25,094 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)

12:34:25,094 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)

12:34:25,094 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216)

12:34:25,094 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542)

12:34:25,095 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524)

12:34:25,095 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:126)

12:34:25,095 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)

12:34:25,095 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)

12:34:25,096 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)

12:34:25,096 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

12:34:25,096 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)

12:34:25,096 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)

12:34:25,096 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)

12:34:25,097 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)

12:34:25,097 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)

12:34:25,097 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)

12:34:25,097 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)

12:34:25,097 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)

12:34:25,097 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)

12:34:25,098 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)

12:34:25,098 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)

12:34:25,098 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)

12:34:25,098 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)

12:34:25,098 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920)

12:34:25,099 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at java.lang.Thread.run(Thread.java:744)

0 个答案:

没有答案