Computing.Net > Forums > Programming > SQL / Oracle / Java Problem with results

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SQL / Oracle / Java Problem with results

Reply to Message Icon

Name: Edwin
Date: July 8, 2002 at 08:05:27 Pacific
Comment:

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("");

}
}



Sponsored Link
Ads by Google

Response Number 1
Name: gpp
Date: July 8, 2002 at 09:17:09 Pacific
Reply:

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..


0

Response Number 2
Name: AndreasF
Date: July 9, 2002 at 10:23:49 Pacific
Reply:

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

//Keep it real


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


VC++ & MySQL FTP Users



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: SQL / Oracle / Java Problem with results

java: problem with loop and random www.computing.net/answers/programming/java-problem-with-loop-and-random/7789.html

Oracle/Java external authentication www.computing.net/answers/programming/oraclejava-external-authentication/13566.html

Problem with Java Mail www.computing.net/answers/programming/problem-with-java-mail/12388.html