Hello, I made Web Service which connect to database and retrieve data. Web service works file, I can connect to database and get data, here is my code:
package mypack;
import javax.jws.WebService;
import javax.jws.WebMethod;
import java.util.*;
import java.sql.*;
import getInfo.*;
/**
*
* @author Aziz
*/
@WebService()
public class RetrieveInfoWS {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
@WebMethod(operationName = "getInfo")
public RetrieveInfo[] getInfo() {
List<RetrieveInfo> list = new ArrayList<RetrieveInfo>();
RetrieveInfo retrieve = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@****:1521:xe", "****", "****");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from Customers");
while(rs.next()){
retrieve = new RetrieveInfo();
retrieve.setCust_Id(rs.getString(1));
retrieve.setCust_fname(rs.getString(2));
retrieve.setCust_lname(rs.getString(3));
retrieve.setCust_address(rs.getString(4));
retrieve.setCust_city(rs.getString(5));
retrieve.setCust_phone(rs.getString(6));
retrieve.setCust_email(rs.getString(7));
list.add(retrieve);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return (RetrieveInfo[])list.toArray(new RetrieveInfo[list.size()]);
}
}
The problem is my web service client application. It cannot get data. My code is following:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*,getInfo.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello DBWS</h1>
<%-- start web service invocation --%><hr/>
<%
String Cust_Id;
String Cust_fname;
String Cust_lname;
String Cust_address;
String Cust_city;
String Cust_phone;
String Cust_email;
try {
mypack.RetrieveInfoWSService service = new mypack.RetrieveInfoWSService();
mypack.RetrieveInfoWS port = service.getRetrieveInfoWSPort();
java.util.List<mypack.RetrieveInfo> list = port.getInfo();
//out.println("Result = "+result);
RetrieveInfo retInfo = new RetrieveInfo();
Iterator p = list.iterator();
out.print("<table border='1'>");
while(p.hasNext()){
retInfo = (RetrieveInfo)p.next();
Cust_Id=retInfo.getCust_Id();
Cust_fname=retInfo.getCust_fname();
Cust_lname=retInfo.getCust_lname();
Cust_address=retInfo.getCust_address();
Cust_city=retInfo.getCust_city();
Cust_phone=retInfo.getCust_phone();
Cust_email=retInfo.getCust_email();
out.print("<tr><td>"+Cust_Id+"</td>");
out.print("<td>"+Cust_fname+"</td>");
out.print("<td>"+Cust_lname+"</td>");
out.print("<td>"+Cust_address+"</td>");
out.print("<td>"+Cust_city+"</td>");
out.print("<td>"+Cust_phone+"</td>");
out.print("<td>"+Cust_email+"</td></tr>");
}
} catch (Exception ex) {
}
out.print("</table>");
%>
<hr/>
</body>
</html>
can anyone tell me what is my problem?
Thanks in advance!!!