• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a weird thing, please help.

 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used a class (Connect) to make connection to a database. Then I use a jsp to call a method (returnTable) of (Connect), which should return an object of ResultSet. The code looks like this:
<%@ page import="Connect" %>
<%@ page import="java.sql.*" %>
<% Connect c = new Connect();
ResultSet rs=c.returnTable(); %>
The result is that c is not null but rs is null. I tried to use another java class to do the same thing as the jsp file. Everything is fine and rs is not null.
Why would the error happen in jsp? Thanks.
[ July 22, 2003: Message edited by: Yuan Ye ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page import="Connect" %>
This isn't legal syntax, at least not with Java 1.4. You need to put your Connect class in a package, and use the package name in your "page import" tags.
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I fixed the way of import, but the problem remains the same. I post the methods below.
When I call the two methods from jsp or servlet.
returnSS() will be fine. However returnTable() returns null. But if I call the two methods in a java application, both are fine. "con" is a valid Connection object.

public String returnSS(){
{return "hello";}
}
public ResultSet returnTable(){
ResultSet rs = null;
try{
Statement stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM ACCOUNT");
}
catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return rs;
}
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found the problem is in the line of "Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");". Which is just fine when I use in a java application. But if I use this line in jsp or servlet in Tomcat. It results exception. Could anyone help me to solve this problem? Thanks
 
Tim Holloway
Saloon Keeper
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes a "Class.forName(~~~~~).newInstance()" may be needed to actually cause things to get rolling. Usually it's older systems that have that problem.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the .jar file containing that class installed in your web application's WEB-INF/lib directory?
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OH, god. Thank you Ron. You are right. After I copy those .jar files into WEB-INF/lib, everything is fine. I was thinking since the .jar files are in classpath, Tomcat will be able to find it. Obvious this is not enough. Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic