N
Nishi Bhonsle
Hi:
I have a client(html web form) accessing data from a schema of an Oracle 9.2 database via a servlet. I created a new table in the same schema of the database and inserted some records in it. I am able to run queries on that table from sqlplus but when i run it via the servlet, i get "0 rows retrieved"-- no data matched that query. Can someone let me know why the servlet cannot see that data?
Thanks much,
Nishi
table structure -->
table name-- "cust"
fields -- name char(20), ssn char(10),address char(40),code number
The servlet program is -->
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
import java.io.*;
public class GetCustomerInfo2 extends HttpServlet {
DataSource ds = null;
Connection conn = null;
public void init() throws ServletException {
try {
InitialContext ic = new InitialContext();
ds = (DataSource) ic.lookup("jdbc/OracleDS");
conn = ds.getConnection();
}
catch (SQLException se) {
throw new ServletException(se);
}
catch (NamingException ne) {
throw new ServletException(ne);
}
}
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String colname = "code";
int retval;
String query = "select code from cust ";
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head><title>GetCustomerInfo</title></head>");
out.println("<body>");
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
retval = rs.findColumn(colname);
//out.println("<table border=1 width=50%>");
//out.println("<tr><th width=25%>Name</th><th width=25%>SSN</th><th width=25%>Address</th><th width=25%>Code</th></tr>");
int count=0;
while (rs.next()) {
count++;
out.println("<tr><td>" + rs.getInt(retval) + "</td></tr>");
}
out.println("</table>");
out.println("<h3>" + count + " rows retrieved</h3>");
rs.close();
stmt.close();
}
catch (SQLException se) {
se.printStackTrace(out);
}
out.println("</body></html>");
}
public void destroy() {
try {
conn.close();
}
catch (SQLException se) {
se.printStackTrace();
}
}
}
I have a client(html web form) accessing data from a schema of an Oracle 9.2 database via a servlet. I created a new table in the same schema of the database and inserted some records in it. I am able to run queries on that table from sqlplus but when i run it via the servlet, i get "0 rows retrieved"-- no data matched that query. Can someone let me know why the servlet cannot see that data?
Thanks much,
Nishi
table structure -->
table name-- "cust"
fields -- name char(20), ssn char(10),address char(40),code number
The servlet program is -->
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
import java.io.*;
public class GetCustomerInfo2 extends HttpServlet {
DataSource ds = null;
Connection conn = null;
public void init() throws ServletException {
try {
InitialContext ic = new InitialContext();
ds = (DataSource) ic.lookup("jdbc/OracleDS");
conn = ds.getConnection();
}
catch (SQLException se) {
throw new ServletException(se);
}
catch (NamingException ne) {
throw new ServletException(ne);
}
}
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String colname = "code";
int retval;
String query = "select code from cust ";
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head><title>GetCustomerInfo</title></head>");
out.println("<body>");
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
retval = rs.findColumn(colname);
//out.println("<table border=1 width=50%>");
//out.println("<tr><th width=25%>Name</th><th width=25%>SSN</th><th width=25%>Address</th><th width=25%>Code</th></tr>");
int count=0;
while (rs.next()) {
count++;
out.println("<tr><td>" + rs.getInt(retval) + "</td></tr>");
}
out.println("</table>");
out.println("<h3>" + count + " rows retrieved</h3>");
rs.close();
stmt.close();
}
catch (SQLException se) {
se.printStackTrace(out);
}
out.println("</body></html>");
}
public void destroy() {
try {
conn.close();
}
catch (SQLException se) {
se.printStackTrace();
}
}
}