i have written the following code with JBuilder, and it works well with
Tomcat, but it cannot be run if i place it into some
existing application of WAS, can any1 help me?
package untitled25;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class Servlet1 extends HttpServlet {
private static final
String CONTENT_TYPE = "text/html";
/**Initialize global variables*/
public void init() throws ServletException {
}
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("
The
servlet has received a GET. This is the reply.
");
jdbcConn(out);
out.println("</body></html>");
}
public void jdbcConn(PrintWriter out)
{
String cmd = null;
int rc;
Connection conn = null;
String newURL = "jdbc:informix-sqli:";
newURL = newURL + "//157.168.136.20:15260/stores:informixserver=hkgrs010_ol1;";
newURL = newURL + "user=informix;password=informix";
out.println("Connection starting....");
try
{
Class.forName("com.informix.jdbc.IfxDriver");
}
catch(Exception e)
{
System.out.println("ERROR: failed to load informix
JDBC driver.");
e.printStackTrace();
}
try
{
conn = DriverManager.getConnection(newURL,"informix","informix");
}
catch (SQLException e)
{
System.out.println("ERROR: failed to connect!");
e.printStackTrace();
}
try
{
Statement stmt = conn.createStatement();
cmd = "select * from location";
ResultSet rs = stmt.executeQuery(cmd);
int i = 0;
out.println("location_id,loc_type");
while(rs.next())
{
String value1 = rs.getString("location_id");
String value2 = rs.getString("loc_type");
out.println("
row " + i + " : " + value1 + value2 + "
");
i++;
}
rs.close();
stmt.close();
}
catch(SQLException e)
{
System.out.println("ERROR: execution failed - statment: " + cmd);
System.out.println("ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public void destroy() {
}
}