Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA Web服务,不与数据库通信_Java_Database_Web Services_Jax Ws - Fatal编程技术网

JAVA Web服务,不与数据库通信

JAVA Web服务,不与数据库通信,java,database,web-services,jax-ws,Java,Database,Web Services,Jax Ws,我正在尝试使用JavaWeb服务与SQLServer数据库通信。在部署和测试web服务之后,我尝试了它的一些方法,但没有任何更改反映在数据库中。例如: @WebMethod(operationName = "readPerson") public String readPerson(@WebParam(name = "ID") long id) { String s = null; try { String connect

我正在尝试使用JavaWeb服务与SQLServer数据库通信。在部署和测试web服务之后,我尝试了它的一些方法,但没有任何更改反映在数据库中。例如:

@WebMethod(operationName = "readPerson")
    public String readPerson(@WebParam(name = "ID") long id)
    {
        String s = null;

        try {
            String connectionUrl= "jdbc:sqlserver://localhost:1433;" +
                        "databaseName=myDatabase;user=sa;password=password;";
            con = DriverManager.getConnection(connectionUrl);

            Statement myStmt  = con.createStatement();

            String query = "SELECT * FROM People WHERE ID=" + id;
            ResultSet rs =  myStmt.executeQuery(query);

            String name = null;
            String surname = null;
            int age = 0;
            long contact = 0;
            String location= null;

            while(rs.next())
            {
                name = rs.getString("Name");            
                surname = rs.getString("Surname");           
                age = rs.getInt("Age");
                contact = rs.getLong("Contact");
                location = rs.getString("Location");
            }

            s =
            "ID: " + Long.toString(id)
            + "\nName: " + name
            + "\nSurname: " + surname
            + "\nAge: " + Integer.toString(age)
            + "\nContact: " + Long.toString(contact)
            + "\nLocation: " + location;


        } catch (SQLException ex) {
            Logger.getLogger(JavaService.class.getName()).log(Level.SEVERE, null, ex);
        }

        return s;

    }   
调用web方法时:

readPerson Method invocation

Method parameter(s)
Type    Value
long    1001
Method returned
java.lang.String : "null"
SOAP Request

    <?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
        <S:Header/>
        <S:Body>
            <ns2:readPerson xmlns:ns2="http://javaservice/">
                <ID>1001</ID>
            </ns2:readPerson>
        </S:Body>
    </S:Envelope>

SOAP Response

    <?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
        <S:Body>
            <ns2:readPersonResponse xmlns:ns2="http://javaservice/"/>
        </S:Body>
    </S:Envelope>

尽管有代码,但这里并没有任何东西可供人们使用。如果您无法实时调试web服务以了解发生了什么,那么您可以做的最好的事情就是在代码中添加更多日志语句以了解您的请求发生了什么;所以我们可以看到异常的响应。我添加了Glassfish输出面板信息。请注意,调用服务不会导致任何错误。没有例外,什么都没有。好像它能工作,但什么也不做凯文,我怎样调试服务?我唯一的选择是在部署后测试它。
Jan 26, 2012 1:28:32 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on Felix platform
Welcome to Felix
================
INFO: Perform lazy SSL initialization for the listener 'http-listener-2'
INFO: Starting Grizzly Framework 1.9.18-o - Thu Jan 26 13:28:36 CET 2012
INFO: Starting Grizzly Framework 1.9.18-o - Thu Jan 26 13:28:36 CET 2012
INFO: Grizzly Framework 1.9.18-o started in: 155ms listening on port 4848
INFO: Grizzly Framework 1.9.18-o started in: 185ms listening on port 8181
INFO: Grizzly Framework 1.9.18-o started in: 165ms listening on port 7676
INFO: Grizzly Framework 1.9.18-o started in: 229ms listening on port 8080
INFO: Grizzly Framework 1.9.18-o started in: 196ms listening on port 3700
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
INFO: SEC1002: Security Manager is OFF.
INFO: Security startup service called
INFO: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
INFO: Realm admin-realm of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
INFO: Realm file of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
INFO: Realm certificate of classtype com.sun.enterprise.security.auth.realm.certificate.CertificateRealm successfully created.
INFO: Security service(s) started successfully....
INFO: Created HTTP listener http-listener-1 on port 8080
INFO: Created HTTP listener http-listener-2 on port 8181
INFO: Created HTTP listener admin-listener on port 4848
INFO: Created virtual server server
INFO: Created virtual server __asadmin
INFO: Virtual server server loaded system default web module
INFO: Initializing Mojarra 2.0.2 (FCS b10) for context '/JAVAWebClient'
INFO: Loading application JAVAWebClient at /JAVAWebClient
INFO: Loading JAVAWebClient Application done is 8391 ms
INFO: Initializing Mojarra 2.0.2 (FCS b10) for context '/WebApplication2'
INFO: Loading application WebApplication2 at /WebApplication2
INFO: Loading WebApplication2 Application done is 1092 ms
INFO: WS00018: Webservice Endpoint deployed
 JavaService  listening at address at http://localhost:8080/JAVAWebService/JavaService
INFO: Loading application JAVAWebService at /JAVAWebService
INFO: Loading JAVAWebService Application done is 747 ms
INFO: GlassFish Server Open Source Edition 3.0.1 (22) startup time : Felix(2951ms) startup services(11001ms) total(13952ms)
INFO: Binding RMI port to *:8686
INFO: JMXStartupService: Started JMXConnector, JMXService URL = service:jmx:rmi://Owner-PC:8686/jndi/rmi://Owner-PC:8686/jmxrmi
INFO: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: [Thread[GlassFish Kernel Main Thread,5,main]] started
INFO: Created HTTP listener http-listener-1 on port 8080
INFO: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = C:\Users\Owner\GlassFish_Server\glassfish\modules\autostart, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = C:\Users\Owner\AppData\Local\Temp\fileinstall--5829618408382097172, felix.fileinstall.filter = null}
INFO: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = C:\Users\Owner\GlassFish_Server\glassfish\domains\domain1\autodeploy\bundles, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = C:\Users\Owner\AppData\Local\Temp\fileinstall-4786743129504536536, felix.fileinstall.filter = null}
INFO: Grizzly Framework 1.9.18-o started in: 81ms listening on port 8080
INFO: Started bundle: file:/C:/Users/Owner/GlassFish_Server/glassfish/modules/autostart/osgi-web-container.jar
INFO: Started bundle: file:/C:/Users/Owner/GlassFish_Server/glassfish/modules/autostart/org.apache.felix.scr.jar
INFO: Perform lazy SSL initialization for the listener 'http-listener-2'
INFO: Created HTTP listener http-listener-2 on port 8181
INFO: Grizzly Framework 1.9.18-o started in: 71ms listening on port 8181
INFO: Updating configuration from org.apache.felix.fileinstall-autodeploy-bundles.cfg
INFO: Installed C:\Users\Owner\GlassFish_Server\glassfish\modules\autostart\org.apache.felix.fileinstall-autodeploy-bundles.cfg
INFO: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = C:\Users\Owner\GlassFish_Server\glassfish\domains\domain1\autodeploy\bundles, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = C:\Users\Owner\AppData\Local\Temp\fileinstall--5770451782291429715, felix.fileinstall.filter = null}
INFO: WS00018: Webservice Endpoint deployed
 JavaService  listening at address at http://localhost:8080/JAVAWebService/JavaService
INFO: Loading application JAVAWebService at /JAVAWebService
INFO: JAVAWebService was successfully deployed in 849 milliseconds.
INFO: WSP5018: Loaded WSIT configuration from file: file:/C:/Users/Owner/Documents/NetBeansProjects/JAVAWebService/build/web/WEB-INF/classes/META-INF/wsit-javaservice.JavaService.xml.
INFO: Metro monitoring rootname successfully set to: amx:pp=/mon/server-mon[server],type=WSEndpoint,name=/JAVAWebService-JavaService-JavaServicePort
INFO: parsing WSDL...

INFO: generating code...

INFO: compiling code...

INFO: Invoking wsimport with http://localhost:8080/JAVAWebService/JavaService?WSDL
INFO: wsimport successful
INFO: parsing WSDL...

INFO: generating code...

INFO: compiling code...

INFO: Invoking wsimport with http://localhost:8080/JAVAWebService/JavaService?WSDL
INFO: wsimport successful
SEVERE: The log message is null.