B
ben
I have the following object on my server:
User.java
-------------------------------
public class User {
private Connection con;
private Statement stmt;
public User() {
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con =
DriverManager.getConnection("jdbc:mysql://localhost.localdomain/blah?user=blah");
stmt = con.createStatement();
} catch (Exception e){
e.printStackTrace();
}
}
/*auxiliary method for getMembers(String), so that you don't
have to pass anything if you want all the members*/
public ResultSet getMembers() {
return getMembers(null);
}
public ResultSet getMembers(String param) {
String sql = null;
if(param == null){
sql = "SELECT * FROM Member";
}
/* check to make sure that a value has been assigned to sql
if not, then it is a good form of error checking and
we'll possibly throw an exception later */
try{
return stmt.executeQuery(sql);
} catch(Exception e){
e.printStackTrace();
return null;
}
}
protected void finalize() throws Throwable{
super.finalize();
stmt.close();
con.close();
}
}
and I have this driver class:
driver.java
------------------
public class driver {
public static void main(String[] args){
User u = new User();
ResultSet r = u.getMembers();
try {
r.next();
System.out.println(r.getString("user_name"));
} catch (Exception e) {
System.out.println("prob in driver");
}
}
}
I can run driver fine if I use the following command:
java -cp .:/usr/local/jakarta-tomcat-4.1.29/common/lib/mysql-connector-java-3.0.11-stable-bin.jar
driver
so I know that the object works. the problem occurs when I try to
instantiate this object within a jsp page. it gives me an error,
telling me that it can't find the driver com.mysql.jdbc.Driver
I think I somehow need to set the classpath under which my jsp pages
operate, since I get the same error if I try to run:
java driver
without giving the classpath.
I've placed the driver within $CATALINA_HOME/common/lib/
so I'm not really sure why my jsp pages are not able to find the
driver class.
Does anybody have any ideas?
Thanks you,
Ben
User.java
-------------------------------
public class User {
private Connection con;
private Statement stmt;
public User() {
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con =
DriverManager.getConnection("jdbc:mysql://localhost.localdomain/blah?user=blah");
stmt = con.createStatement();
} catch (Exception e){
e.printStackTrace();
}
}
/*auxiliary method for getMembers(String), so that you don't
have to pass anything if you want all the members*/
public ResultSet getMembers() {
return getMembers(null);
}
public ResultSet getMembers(String param) {
String sql = null;
if(param == null){
sql = "SELECT * FROM Member";
}
/* check to make sure that a value has been assigned to sql
if not, then it is a good form of error checking and
we'll possibly throw an exception later */
try{
return stmt.executeQuery(sql);
} catch(Exception e){
e.printStackTrace();
return null;
}
}
protected void finalize() throws Throwable{
super.finalize();
stmt.close();
con.close();
}
}
and I have this driver class:
driver.java
------------------
public class driver {
public static void main(String[] args){
User u = new User();
ResultSet r = u.getMembers();
try {
r.next();
System.out.println(r.getString("user_name"));
} catch (Exception e) {
System.out.println("prob in driver");
}
}
}
I can run driver fine if I use the following command:
java -cp .:/usr/local/jakarta-tomcat-4.1.29/common/lib/mysql-connector-java-3.0.11-stable-bin.jar
driver
so I know that the object works. the problem occurs when I try to
instantiate this object within a jsp page. it gives me an error,
telling me that it can't find the driver com.mysql.jdbc.Driver
I think I somehow need to set the classpath under which my jsp pages
operate, since I get the same error if I try to run:
java driver
without giving the classpath.
I've placed the driver within $CATALINA_HOME/common/lib/
so I'm not really sure why my jsp pages are not able to find the
driver class.
Does anybody have any ideas?
Thanks you,
Ben