Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems with java

 
maria pasha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone!

im a novice when it comes to JSP ..im still learning and also facing problems!

im using JRUN as web server and all im trying to do is retrieve records from a database:

this is my code:


<%@page language="java" import="java.sql.*" import = "java.util.*" import="java.io.*" %>

<html>
<head>

<title>
JSP Example 2
</title>
</head>
<body>
<h1>JSP Example 3</h1>
<%
String place;
Connection dbconn;
ResultSet results;
PreparedStatement sql;
try
{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try
{

boolean doneheading = false;
String answer;

dbconn = DriverManager.getConnection("jdbc dbc GT3","","");

sql = dbconn.prepareStatement("SELECT * FROM NLCHART");
results = sql.executeQuery();



while(results.next())

{

if(! doneheading)
{
out.println("<table border=2>");
doneheading = true;
}


place=results.getString(1);
}
if(doneheading)
{
out.println("</table>");
}
else
{
out.println("No matches");


}

}
catch (SQLException s)
{
out.println("SQL Error<br>");
}
}
catch (ClassNotFoundException err)
{
out.println("Class loading error");
}

%>
</body>
</html>

ive copied all of it..

im getting compile errors eg error : type Connection not found etc!

my constraint is that i have to use Jrun although this code works with Tomcat.

Please Help me! im seriously worried!
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you paste actual error messages you are getting ? with the line numbers etc etc

Shailesh
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem might be this statement:
<%@page language="java" import="java.sql.*" import = "java.util.*" import="java.io.*" %>

I think the correct syntax would be:
<%@page import="java.sql.*,java.util.*,java.io.*" %>

I'm not sure you can specify the language in the same statement, or whether you need a separate one; but it's probably unnecessary anyway.

(Since you state that you're just beginning with JSP, I'm going to gloss over the fact that it's generally considered to be bad style to have database code in JSP pages, as well as the problems the JDBC/ODBC bridge will cause you in a multi-threaded environment like a servlet container is.)
 
maria pasha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

i have tried what you asked and its still not working :S and yes i am very aware of the fact that java snippets in jsp is considered to be a unprofessional style of coding but at this point i cannot do much about that as i have some constraints which i cannot disclose.

52. Connection dbconn;
<-------->
*** Error: Type Connection was not found.


53. ResultSet results;
<------->
*** Error: Type ResultSet was not found.


54. PreparedStatement sql;
<--------------->
*** Error: Type PreparedStatement was not found.



these are the errors i am getting. I think it is because it cannot find the library path but i have copied tools.jar into jrun but to no avail
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't worked with J-Run but it seems J run is unable to use java.sql classes try to find out how J run uses JDK because all these class are related to JDK.

Shailesh
[ July 06, 2005: Message edited by: Shailesh Chandra ]
 
maria pasha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i cant seem to find anything that could help me on that!

there is more documentation on tomcat than jrun on the web!
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it has anything to do with JRun. The classes are part of the standard class library, not tools.jar, so if they weren't available you wouldn't be able to run any Java code (including JRun).
It looks like you aren't importing the java.sql package properly. Did you change the import statement in your JSP page like I suggested?
 
maria pasha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i did and its not working!!! what to do?

another thing.

for example i have created a new folder in C root and have a web-inf folder in it....how am i supposed to configure the web.xml files and the jrun-web.xml files?
 
Srilakshmi Vara
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maria,

To decide whether its the problem with the class files try to write another jsp which has lang package classes, if it works then there is a problem with your import,

<%@page import="java.sql.*,java.io.*;"%>

Srilakshmi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic