You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@xml.apache.org by Founaboui Haman <ha...@online.de> on 2002/08/05 11:42:41 UTC
Re: Looking for samples...
Hello Erich Izdepski,
thank your for ur answer, but I am not using an app server. I wrote a service that retrieve data from a database and its working well, when I ran it outside a web service.
But as a web service I am getting only null as response. And catalina is outputting this exception: org/gjt/mm/mysql/Driver, which i don't know what it means. I install the Driver as explained in the docs of the Driver. Please help me. I attached the service and the client to this mail.
Thank you helping me!
Haman
----- Original Message -----
From: Erich Izdepski
To: soap-user@xml.apache.org
Sent: Monday, July 29, 2002 4:47 PM
Subject: RE: Looking for samples...
A class implementing a web service is nothing magical. If you want to know how to access a database, look at any jdbc examples. If in an app server, just use the built-in database connection pool. Use jndi to get a handle to it and your in business.
Here is some test code (not production quality) that does exactly what I described above on JBoss 2.4.4 w/catalina.
<%@page import="javax.sql.*, java.sql.*, javax.naming.*, java.util.Hashtable" %>
<%
DataSource ds = null;
Connection con = null;
Context ctx = null;
Hashtable env = null;
Statement stmt = null;
ResultSet rs = null;
// Set up environment for creating InitialContext object
env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "http://localhost:1099");
try
{
// Retrieve the DataSource object that bound to the logical
// lookup JNDI name
ctx = new InitialContext(env);
ds = (DataSource) ctx.lookup("java:/DefaultDS");
if (ds != null)
{
out.println("got a data source from JBoss JNDI<br/>");
}
}
catch (NamingException eName)
{
out.println("Error looking up 'java:/DefaultDS': " +eName);
}
// Get Database Connection
try
{
con = ds.getConnection("sa", "");
con.setAutoCommit(true);
out.print("got a hypersonic database connection<br/>");
stmt = con.createStatement();
//create a table
String createString = "create table SUPPLIERS " +
"(SUP_ID int, " +
"SUP_NAME varchar(40), " +
"STREET varchar(40), " +
"CITY varchar(20), " +
"STATE char(2), ZIP char(5))";
stmt = con.createStatement();
stmt.executeUpdate(createString);
out.print("created the SUPPLIERS table<br/>");
//add some data
stmt.executeUpdate("insert into SUPPLIERS " +
"values(49, 'Superior Coffee', '1 Party Place', " +
"'Mendocino', 'CA', '95460')");
stmt.executeUpdate("insert into SUPPLIERS " +
"values(101, 'Acme, Inc.', '99 Market Street', " +
"'Groundsville', 'CA', '95199')");
stmt.executeUpdate("insert into SUPPLIERS " +
"values(150, 'The High Ground', '100 Coffee Lane', " +
"'Meadows', 'CA', '93966')");
out.print("inserted data into the SUPPLIERS table<br/>");
//query the table
String query = "select * " +
"from SUPPLIERS ";
rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
int rowCount = 1;
while (rs.next())
{
out.print("Row " + rowCount + ": <br/>");
for (int i = 1; i <= numberOfColumns; i++)
{
out.print(" Column " + i + ": ");
out.println(rs.getString(i) + "<br/>");
}
out.print("<br/>");
rowCount++;
}
//delete the table
stmt.executeUpdate("drop table SUPPLIERS");
out.print("dropped the SUPPLIERS table<br/>");
//cleanup
stmt.close();
// Close Database Connection
if (con != null) con.close();
}
catch (SQLException eCon)
{
out.println("Error getting a connection: " + eCon);
}
%>
Erich Izdepski
Senior Software Engineer
Cysive, Inc.
-----Original Message-----
From: Founaboui Haman [mailto:haman@online.de]
Sent: Monday, July 29, 2002 1:03 AM
To: soap-user@xml.apache.org
Subject: Looking for samples...
Hello together,
do any one knows, where I can find a web service sample, that uses a backend database.
I will be grateful
Haman