axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anthony v" <antho...@cvsol.com>
Subject AXIS2 - MySQL - Database connection code
Date Sun, 08 Oct 2006 01:36:31 GMT
Hi all

I'm rather new to java having come from more of a classic vb, .net, C#, etc
background and am just running into a little bit of trouble with AXIS2 web
service that I am trying to write and some database connection code that
needs to happen. 

 

Basically the web service runs but it just returns an empty soap message:

 

<?xml version='1.0' encoding='UTF-8'?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <soapenv:Header />

  <soapenv:Body>

    <ns1:RetrieveMedicalCentreResponse
xmlns:ns1="http://AustMedicalCentreAssoc.org/" />

  </soapenv:Body>

</soapenv:Envelope>

 

 

Now creating the service WSDL first and when I initially filled the Skeleton
with static value it worked fine:

 

/**

 * AustMedicalCentreAssocSkeleton.java

 *

 * This file was auto-generated from WSDL

 * by the Apache Axis2 version: 1.0 May 05, 2006 (12:31:13 IST)

 */

package org.apache.axis2;

 

import java.util.Calendar;

/**

 *  AustMedicalCentreAssocSkeleton java skeleton for the axisService

 */

public class AustMedicalCentreAssocSkeleton

{

 

      /**

      * Auto generated method signature 

      * @param objInputSearchMedicalCentre 

      */

      public org.austmedicalcentreassoc.SearchMedicalCentreResponse
SearchMedicalCentre(org.austmedicalcentreassoc.SearchMedicalCentre
objInputSearchMedicalCentre)

      {

            /**   //Input variables that will be bound to the 

             *          objInputSearchMedicalCentre.getStrCenterName();

             *          objInputSearchMedicalCentre.getStrCenterAbbrv();

             *
objInputSearchMedicalCentre.getIntCenterTypeCodeID();

             *          objInputSearchMedicalCentre.getStrCenterType();

             */

 

            //This creates the student record/instance 

            org.austmedicalcentreassoc.MedicalCentreDetailSummary
objMedicalCenterSummaryInstanceTemp = new
org.austmedicalcentreassoc.MedicalCentreDetailSummary();

 

            objMedicalCenterSummaryInstanceTemp.setHealthCenterID(1);

            objMedicalCenterSummaryInstanceTemp.setCenterTypeCodeID(1);

            objMedicalCenterSummaryInstanceTemp.setCenterType("Hospital");

            objMedicalCenterSummaryInstanceTemp.setCenterName("Royal
Brisbane");

            objMedicalCenterSummaryInstanceTemp.setCenterAbbrev("RB");

 

            //This creates the wrapper which needs to have the student set
against it 

            org.austmedicalcentreassoc.SearchMedicalCentreResponse
objMedicalCenterSummaryTemp = new
org.austmedicalcentreassoc.SearchMedicalCentreResponse();

            for ( int i = 0; i < 5; i++ )

 
objMedicalCenterSummaryTemp.addSearchMedicalCentreResult(objMedicalCenterSum
maryInstanceTemp);

 

            return objMedicalCenterSummaryTemp;

      } 

}

 

But when I transferred it over to the database version of the code I get the
empty message provided above. I am assuming the reason why I just get the
empty message back is because there is an error somewhere in the try catch
blocks below but I have no idea what that might be. Now I realise that the
code mightn't be the prettiest looking code or the best way of connecting to
the database but as I said I am rather new to java and when I tried
abstracting out the database connection code I ran into a variety of issues
so hear it is:

/**

* AustMedicalCentreAssocSkeleton.java

*

* This file was auto-generated from WSDL

* by the Apache Axis2 version: SNAPSHOT Oct 08, 2006 (12:23:54 GMT+00:00)

*/

package org.austmedicalcentreassoc;

 

import java.util.Calendar;

import java.sql.*;

 

/**

 *  AustMedicalCentreAssocSkeleton java skeleton for the axisService

 */

public class AustMedicalCentreAssocSkeleton

{

 

      /**

      * Auto generated method signature 

      * @param objInputSearchMedicalCentre 

      */

      public org.austmedicalcentreassoc.SearchMedicalCentreResponse
SearchMedicalCentre(org.austmedicalcentreassoc.SearchMedicalCentre
objInputSearchMedicalCentre)

      {

            //Input variables that will be bound to the 

            String strCentreName =
objInputSearchMedicalCentre.getStrCentreName();

            String strCentreAbbrv =
objInputSearchMedicalCentre.getStrCentreAbbrv();

            int intCentreTypeCodeID =
objInputSearchMedicalCentre.getIntCentreTypeCodeID();

            String strCentreType =
objInputSearchMedicalCentre.getStrCentreType(); 

 

            //Builds up the where clase on for the SQL 

            String strSQL = "";

            if (strCentreName.length() > 0) strSQL += "AND centre_name = '"
+ strCentreName + "'";

            if (strCentreAbbrv.length() > 0) strSQL += "AND centre_abbrev =
'" + strCentreAbbrv + "'";

            if (intCentreTypeCodeID > 0) strSQL += "AND centre_type_code_id
= '" + intCentreTypeCodeID + "'";

            if (strCentreType.length() > 0) strSQL += "AND code_name = '" +
strCentreType + "'";

            if (strSQL.length() > 0) strSQL = "WHERE " +
strSQL.substring(4); 

 

            //This creates the student record/instance 

            org.austmedicalcentreassoc.MedicalCentreDetailSummary
objMedicalCentreSummaryInstanceTemp = new
org.austmedicalcentreassoc.MedicalCentreDetailSummary();

            //This creates the wrapper which needs to have the student set
against it 

            org.austmedicalcentreassoc.SearchMedicalCentreResponse
objMedicalCentreSummaryTemp = new
org.austmedicalcentreassoc.SearchMedicalCentreResponse();

            //Statement that is created to execute the database connection
statement 

            Statement objStatement;

            //Results set that will contain the database results 

            ResultSet objResultSet;

 

            //Try and open database connection 

            try

            {

                  //Register the JDBC driver for MySQL.

                  Class.forName("com.mysql.jdbc.Driver");

                  //Define URL of database server for database named amca on
the localhost with the default port number 3306.

                  String url = "jdbc:mysql://localhost:3306/amca";

                  //Get a connection to the database for a user named root
with the password ""

                  Connection objConnection =
DriverManager.getConnection(url, "root", "");

                  //Get object initialized as shown.

                  objStatement =
objConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);

                  //Query the database, storing the result in an object of
type ResultSet

                  objResultSet = objStatement.executeQuery("SELECT
health_centre_id, centre_type_code_id, code_name AS centre_type,
centre_name, centre_abbrev FROM health_centre hc_1 LEFT JOIN code_value cv_1
ON hc_1.centre_type_code_id = cv_1.code_id" + strSQL);

 

                  //Use the methods of class ResultSet in a loop to display
all of the data in the database. 

                  while (objResultSet.next())

                  {

                        //Bind each column of the results set to the main
object 

 
objMedicalCentreSummaryInstanceTemp.setHealthCentreID(objResultSet.getInt("h
ealth_center_id"));

 
objMedicalCentreSummaryInstanceTemp.setCentreTypeCodeID(objResultSet.getInt(
"center_type_code_id"));

 
objMedicalCentreSummaryInstanceTemp.setCentreType(objResultSet.getString("ce
nter_type"));

 
objMedicalCentreSummaryInstanceTemp.setCentreName(objResultSet.getString("ce
nter_name"));

 
objMedicalCentreSummaryInstanceTemp.setCentreAbbrev(objResultSet.getString("
center_abbrev"));

                        //Pass the object back to the return method 

 
objMedicalCentreSummaryTemp.addSearchMedicalCentreResult(objMedicalCentreSum
maryInstanceTemp);

                  }

 

                  //Close the connection to the database 

                  objConnection.close(); 

            }

            catch (Exception e)

            {

                  //throw

            }

 

            return objMedicalCentreSummaryTemp;

      }

}

 

Any help here is greatly appreciated

Thanks 

Anthony 


Mime
View raw message