You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Muthana Al-Temimi <mu...@gmx.de> on 2008/10/27 17:14:21 UTC

need help in axis

Hello there,

 

i'm new in Axis and i wrote the following code in java

package logistic.ws.serverside;

 

 

 

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.sql.ResultSet;

 

 

public class AnimalService {

 

      

            final int idVal = 0;

            private String name ;

            private String category;

            private String[] retVal = new String[2];

            

            

            

            

            Connection conn = null;

            

            public  AnimalService () {}

            

            

            public String getAnimals() {

                  return name+category;

            }

 

            

            

          

              public String[] findAnimal(int idVal) {

              

              try

              {

                  String userName = "root";

                  String password = "muthana";

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

                  try {

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

                  }catch (ClassNotFoundException e){

                        System.out.println ( " Unable to load Driver Class
");     

                        

                  }

                  conn = DriverManager.getConnection (url, userName,
password);

                  System.out.println ("Database connection established");

                  Statement s = conn.createStatement ();

                  

                  

                  String query = "SELECT name,category FROM animal where
id="+ idVal +"";

                  

                  System.out.println(query);

                  

                  ResultSet rs = s.executeQuery(query);

                  

                  while (rs.next ())

                  {

                     

                      

                     

                     

                             // animals = rs.getString(1);

                             // category=rs.getString(2);

 

                             /*

                             String nameVal = rs.getString ("name");

                      String catVal = rs.getString ("category");

                      System.out.println ( "id = " + idVal + ", name = " +
nameVal  + ", category = " + catVal);

                              

                      */

                             

                             String X1 = rs.getString(1);

                             String X2 = rs.getString(2);

                             System.out.println (X1);

                             System.out.println (X2);

                             

                             this.name =  X1 ;

                             this.category =  X2 ;

                             

                             

                             // I think that my problem is here 2 string in
array

                             String[] retVal= {X1,X2};

                             

                  }

                  rs.close ();

                  s.close ();

                  

                  

                 

 

              }catch (Exception e)

              {

                  System.err.println ("Cannot connect to database server");

                  System.err.println ("Error message: " + e.getMessage ());

               

                 

              }

              finally

              {

                  if (conn != null)

                  {

                      try

                      {

                          conn.close ();

                          System.out.println ("Database connection
terminated");

                      }

                      catch (Exception e) { /* ignore close errors */ }

                  }

              }

          

              return retVal;

              

             

 

}     

              

              

             

              

      /*

            

                  public static void main (String[] args)

                {

               AnimalService animalws = new AnimalService();

               animalws.findAnimal(1);

              }  // end main method

              

         */    

}     

 

 

      

 

 

The response is wrong as follow:

 

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<findAnimalResponse xmlns="http://serverside.ws.logistic">

<findAnimalReturn xsi:nil="true"/>

<findAnimalReturn xsi:nil="true"/>

</findAnimalResponse>

</soapenv:Body>

</soapenv:Envelope>

 

The request is correct:

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<findAnimal xmlns="http://serverside.ws.logistic">

<idVal>2</idVal>

</findAnimal>

</soapenv:Body>

</soapenv:Envelope>

 

I think my problem is how to map array into string

I need help to fix that to get the result from the database.

 

Any help will be good

 

Thanks

muthana


RE: need help in axis

Posted by "Meeusen, Christopher W." <Me...@mayo.edu>.
As a general rule of thumb I wouldn't keep anything as a member variable
(class variable), they are static and can cause problems with multi
threaded applications.

________________________________

From: axis-user-return-75947-Meeusen.Christopher=mayo.edu@ws.apache.org
[mailto:axis-user-return-75947-Meeusen.Christopher=mayo.edu@ws.apache.or
g] On Behalf Of Pugalia, Jai P (JP)
Sent: Monday, October 27, 2008 11:22 AM
To: axis-user@ws.apache.org
Subject: RE: need help in axis


Muthana,
 
One problem I notice that the assignment is done to a local variable
whereas the method is returning the member variable.
 
// Local variable assignment
String[] retVal= {X1,X2};    // Local variable

 

// Return member variable

return retVal;

 

JP


________________________________

From: Muthana Al-Temimi [mailto:muthana@gmx.de] 
Sent: Monday, October 27, 2008 9:14 AM
To: axis-user@ws.apache.org
Subject: need help in axis



Hello there,

 

i'm new in Axis and i wrote the following code in java

package logistic.ws.serverside;

 

 

 

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.sql.ResultSet;

 

 

public class AnimalService {

 

      

            final int idVal = 0;

            private String name ;

            private String category;

            private String[] retVal = new String[2];

            

            

            

            

            Connection conn = null;

            

            public  AnimalService () {}

            

            

            public String getAnimals() {

                  return name+category;

            }

 

            

            

          

              public String[] findAnimal(int idVal) {

              

              try

              {

                  String userName = "root";

                  String password = "muthana";

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

                  try {

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

                  }catch (ClassNotFoundException e){

                        System.out.println ( " Unable to load Driver
Class ");     

                        

                  }

                  conn = DriverManager.getConnection (url, userName,
password);

                  System.out.println ("Database connection
established");

                  Statement s = conn.createStatement ();

                  

                  

                  String query = "SELECT name,category FROM animal where
id="+ idVal +"";

                  

                  System.out.println(query);

                  

                  ResultSet rs = s.executeQuery(query);

                  

                  while (rs.next ())

                  {

                     

                      

                     

                     

                             // animals = rs.getString(1);

                             // category=rs.getString(2);

 

                             /*

                             String nameVal = rs.getString ("name");

                      String catVal = rs.getString ("category");

                      System.out.println ( "id = " + idVal + ", name = "
+ nameVal  + ", category = " + catVal);

                              

                      */

                             

                             String X1 = rs.getString(1);

                             String X2 = rs.getString(2);

                             System.out.println (X1);

                             System.out.println (X2);

                             

                             this.name =  X1 ;

                             this.category =  X2 ;

                             

                             

                             // I think that my problem is here 2 string
in array

                             String[] retVal= {X1,X2};

                             

                  }

                  rs.close ();

                  s.close ();

                  

                  

                 

 

              }catch (Exception e)

              {

                  System.err.println ("Cannot connect to database
server");

                  System.err.println ("Error message: " + e.getMessage
());

               

                 

              }

              finally

              {

                  if (conn != null)

                  {

                      try

                      {

                          conn.close ();

                          System.out.println ("Database connection
terminated");

                      }

                      catch (Exception e) { /* ignore close errors */ }

                  }

              }

          

              return retVal;

              

             

 

}     

              

              

             

              

      /*

            

                  public static void main (String[] args)

                {

               AnimalService animalws = new AnimalService();

               animalws.findAnimal(1);

              }  // end main method

              

         */    

}     

 

 

      

 

 

The response is wrong as follow:

 

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<findAnimalResponse xmlns="http://serverside.ws.logistic">

<findAnimalReturn xsi:nil="true"/>

<findAnimalReturn xsi:nil="true"/>

</findAnimalResponse>

</soapenv:Body>

</soapenv:Envelope>

 

The request is correct:

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<findAnimal xmlns="http://serverside.ws.logistic">

<idVal>2</idVal>

</findAnimal>

</soapenv:Body>

</soapenv:Envelope>

 

I think my problem is how to map array into string

I need help to fix that to get the result from the database.

 

Any help will be good

 

Thanks

muthana


RE: need help in axis

Posted by "Pugalia, Jai P (JP)" <jp...@avaya.com>.
Muthana,
 
One problem I notice that the assignment is done to a local variable
whereas the method is returning the member variable.
 
// Local variable assignment
String[] retVal= {X1,X2};    // Local variable

 

// Return member variable

return retVal;

 

JP


________________________________

From: Muthana Al-Temimi [mailto:muthana@gmx.de] 
Sent: Monday, October 27, 2008 9:14 AM
To: axis-user@ws.apache.org
Subject: need help in axis



Hello there,

 

i'm new in Axis and i wrote the following code in java

package logistic.ws.serverside;

 

 

 

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.sql.ResultSet;

 

 

public class AnimalService {

 

      

            final int idVal = 0;

            private String name ;

            private String category;

            private String[] retVal = new String[2];

            

            

            

            

            Connection conn = null;

            

            public  AnimalService () {}

            

            

            public String getAnimals() {

                  return name+category;

            }

 

            

            

          

              public String[] findAnimal(int idVal) {

              

              try

              {

                  String userName = "root";

                  String password = "muthana";

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

                  try {

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

                  }catch (ClassNotFoundException e){

                        System.out.println ( " Unable to load Driver
Class ");     

                        

                  }

                  conn = DriverManager.getConnection (url, userName,
password);

                  System.out.println ("Database connection
established");

                  Statement s = conn.createStatement ();

                  

                  

                  String query = "SELECT name,category FROM animal where
id="+ idVal +"";

                  

                  System.out.println(query);

                  

                  ResultSet rs = s.executeQuery(query);

                  

                  while (rs.next ())

                  {

                     

                      

                     

                     

                             // animals = rs.getString(1);

                             // category=rs.getString(2);

 

                             /*

                             String nameVal = rs.getString ("name");

                      String catVal = rs.getString ("category");

                      System.out.println ( "id = " + idVal + ", name = "
+ nameVal  + ", category = " + catVal);

                              

                      */

                             

                             String X1 = rs.getString(1);

                             String X2 = rs.getString(2);

                             System.out.println (X1);

                             System.out.println (X2);

                             

                             this.name =  X1 ;

                             this.category =  X2 ;

                             

                             

                             // I think that my problem is here 2 string
in array

                             String[] retVal= {X1,X2};

                             

                  }

                  rs.close ();

                  s.close ();

                  

                  

                 

 

              }catch (Exception e)

              {

                  System.err.println ("Cannot connect to database
server");

                  System.err.println ("Error message: " + e.getMessage
());

               

                 

              }

              finally

              {

                  if (conn != null)

                  {

                      try

                      {

                          conn.close ();

                          System.out.println ("Database connection
terminated");

                      }

                      catch (Exception e) { /* ignore close errors */ }

                  }

              }

          

              return retVal;

              

             

 

}     

              

              

             

              

      /*

            

                  public static void main (String[] args)

                {

               AnimalService animalws = new AnimalService();

               animalws.findAnimal(1);

              }  // end main method

              

         */    

}     

 

 

      

 

 

The response is wrong as follow:

 

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<findAnimalResponse xmlns="http://serverside.ws.logistic">

<findAnimalReturn xsi:nil="true"/>

<findAnimalReturn xsi:nil="true"/>

</findAnimalResponse>

</soapenv:Body>

</soapenv:Envelope>

 

The request is correct:

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<findAnimal xmlns="http://serverside.ws.logistic">

<idVal>2</idVal>

</findAnimal>

</soapenv:Body>

</soapenv:Envelope>

 

I think my problem is how to map array into string

I need help to fix that to get the result from the database.

 

Any help will be good

 

Thanks

muthana