Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am having a few problems and I cannot explain why this is happening. I am using a Java servlet to connect to an Oracle Database. Using the "SELECT * FROM " command, the servlet is to retrieve all results and display them in an html file. I am using Java servlets and RESIN servlet webserver.
The problem that I am having is that the servlet
a) Doesn't show the results at all. By this I mean that the servlet runs and executes the code, returns and no SQL exception errors but returns empty results.
b) The servlet shows some results. It shows all the results from a different table but when I try to add to the table so that it has 5 records, it only shows 4, as if the code or database does not update.
I can't understand why it would do this. When I execute "SELECT * FROM " it is fine and shows all the results on SQL PLUS*. Could it be my code or anything?
My Code as follows (ost.java):
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;public class ost extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("Text/html");
PrintWriter out = response.getWriter();out.println("");
out.println("Oracle Example");
out.println("");
out.println("");
out.println("Employees");
out.println("");Connection conn = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@IPADDRESS:test1", "system", "manager");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Emptest");
//Print start of table and column headers
out.println("");
out.println("IDNAME");
//Loop through results of query.
while(rs.next())
{
out.println("");
out.println("" + rs.getString("EmpID") + "");
out.println("" + rs.getString("Name") + "");
out.println("");
}out.println("");
}
catch(SQLException e)
{
out.println("SQLException: " + e.getMessage() + "");
while((e = e.getNextException()) != null)
out.println(e.getMessage() + "");
}
catch(ClassNotFoundException e)
{
out.println("ClassNotFoundException: " + e.getMessage() + "");
}
finally
{
//Clean up resources, close the connection.
if(conn != null)
{
try
{
conn.close();
}
catch (Exception ignored) {}
}
}
out.println("");
out.println("");
out.println("");
}
}

Your code looks ok.. Did you try running your sql statement thru a query analyzer? but the sql statement is about as simple as you can get though..

Be sure that you are not logged in at your SQL database when running/compiling the program. Just a tip!
//Keep it real

![]() |
VC++ & MySQL
|
FTP Users
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |