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

时间:2012-01-26 11:27:43

标签: java database web-services jax-ws

我正在尝试使用JAVA Web服务与SQL Server数据库进行通信。在我部署和测试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>

这个方法应该在我的“People”表中返回一个带有记录字段内容的字符串,但是当我测试它时,没有任何反应。也没有错误。奇怪的是,当我在普通应用程序(不是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.

0 个答案:

没有答案