Hello,
When I try to return all items in a MySQL database I keep getting the error below. However, when I change the SQL query string to "SELECT dept FROM time_sheet" in the javaBean and make necessary changes in the jsp file it works fine and all departments show up on the web page.
Strangely, it only works when I use dept in the query.
It does not work for any other field names, eg. lname, fname etc. When I try different field names I get an error saying "Column 'fname' not found".
I have include the jsp and javaBean code below the error. Any help would be greatly appreciated.
C:\Tomcat 4.1\webapps\timeclock\WEB-INF\classes\com\time>java timeclock
Exception in thread "main" java.lang.NoClassDefFoundError: timeclock (wrong name
: com/time/timeclock)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
JAVA_BEAN+++++++++++++++++++++++++++++++++++++++++++
// timeclock.java
package com.time;
import java.sql.*;
import java.util.*;
public class timeclock {
String error;
Connection con;
public timeclock() { }
public void connect() throws ClassNotFoundException,
SQLException,
Exception {
try {
Class.forName("com.mysql.jdbc.Driver"
.newInstance();
System.out.println("JDBC driver loaded"
;
con = DriverManager.getConnection
("jdbc:mysql://mon1/time_clock?user=username&password="
;
System.out.println("Database connection established"
;
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT fname FROM time_sheet"
;
//ResultSet rs= stmt.executeQuery("Select fname, lname FROM time_sheet"
;
while (rs.next()) {
String title = rs.getString("fname"
;
//String title = rs.getString("lname"
;
//float price = rs.getFloat("Price"
;
System.out.println(title);
}
} catch (ClassNotFoundException cnfe) {
System.out.println("ClassNotFoundException: Could not locate driver"
;
} catch (SQLException cnfe) {
System.out.println("SQLException: Could not connect to database"
;
} catch (Exception e) {
System.out.println
("An unknown error occurred while connecting to database"
;
}
}
public void disconnect() throws SQLException {
try {
if ( con !=null ) {
con.close();
}
} catch(SQLException sqle) {
System.out.println("Unable to close database connection."
;
}
}
public ResultSet viewUsers() throws SQLException, Exception {
ResultSet rs= null;
try {
String queryString=("SELECT fname FROM time_sheet"
;
Statement stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
} catch (SQLException sqle) {
error = "SQLException: Could not execute query.";
throw new SQLException(error);
} catch (Exception e) {
error = "An exception has occured while retrieving departments,";
throw new Exception(error);
}
return rs;
}
public static void main (String[] args)
{
timeclock sdb = new timeclock();
try
{
sdb.connect();
}
catch (Exception e)
{
e.printStackTrace();
}
}
JSP+++++++++++++++++++++++++++++++++++++++++++++++++++++
<%@page contentType="text/html" import="java.sql.*, java.util.*" %>
<jsp:useBean id="mytime" class="com.time.timeclock"/>
<html>
<head><title>JSP Page</title></head>
<body>
<H1>BEAN TEST</H1>
<table border="1">
<tr>
<td><b><B>Clock Number:</b></td>
<td><b><B>Date:</b></td>
<td><b><B>Time:</b></td>
<td><b><B>User ID:</b></td>
<td><b><B>First Name:</b></td>
<td><b><B>Last Name:</b></td>
<td><b><B>Departments:</b></td>
<td><b><B>Status:</b></td>
<td><b><B>Record Number:</b></td>
</tr>
<%
mytime.connect();
ResultSet rs = mytime.viewUsers();
while (rs.next()) {
%>
<tr>
<td><%= rs.getString("fname"
%></td>
</tr>
<%
}
%>
</table>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
</body>
</html>
When I try to return all items in a MySQL database I keep getting the error below. However, when I change the SQL query string to "SELECT dept FROM time_sheet" in the javaBean and make necessary changes in the jsp file it works fine and all departments show up on the web page.
Strangely, it only works when I use dept in the query.
It does not work for any other field names, eg. lname, fname etc. When I try different field names I get an error saying "Column 'fname' not found".
I have include the jsp and javaBean code below the error. Any help would be greatly appreciated.
C:\Tomcat 4.1\webapps\timeclock\WEB-INF\classes\com\time>java timeclock
Exception in thread "main" java.lang.NoClassDefFoundError: timeclock (wrong name
: com/time/timeclock)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
JAVA_BEAN+++++++++++++++++++++++++++++++++++++++++++
// timeclock.java
package com.time;
import java.sql.*;
import java.util.*;
public class timeclock {
String error;
Connection con;
public timeclock() { }
public void connect() throws ClassNotFoundException,
SQLException,
Exception {
try {
Class.forName("com.mysql.jdbc.Driver"
System.out.println("JDBC driver loaded"
con = DriverManager.getConnection
("jdbc:mysql://mon1/time_clock?user=username&password="
System.out.println("Database connection established"
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT fname FROM time_sheet"
//ResultSet rs= stmt.executeQuery("Select fname, lname FROM time_sheet"
while (rs.next()) {
String title = rs.getString("fname"
//String title = rs.getString("lname"
//float price = rs.getFloat("Price"
System.out.println(title);
}
} catch (ClassNotFoundException cnfe) {
System.out.println("ClassNotFoundException: Could not locate driver"
} catch (SQLException cnfe) {
System.out.println("SQLException: Could not connect to database"
} catch (Exception e) {
System.out.println
("An unknown error occurred while connecting to database"
}
}
public void disconnect() throws SQLException {
try {
if ( con !=null ) {
con.close();
}
} catch(SQLException sqle) {
System.out.println("Unable to close database connection."
}
}
public ResultSet viewUsers() throws SQLException, Exception {
ResultSet rs= null;
try {
String queryString=("SELECT fname FROM time_sheet"
Statement stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
} catch (SQLException sqle) {
error = "SQLException: Could not execute query.";
throw new SQLException(error);
} catch (Exception e) {
error = "An exception has occured while retrieving departments,";
throw new Exception(error);
}
return rs;
}
public static void main (String[] args)
{
timeclock sdb = new timeclock();
try
{
sdb.connect();
}
catch (Exception e)
{
e.printStackTrace();
}
}
JSP+++++++++++++++++++++++++++++++++++++++++++++++++++++
<%@page contentType="text/html" import="java.sql.*, java.util.*" %>
<jsp:useBean id="mytime" class="com.time.timeclock"/>
<html>
<head><title>JSP Page</title></head>
<body>
<H1>BEAN TEST</H1>
<table border="1">
<tr>
<td><b><B>Clock Number:</b></td>
<td><b><B>Date:</b></td>
<td><b><B>Time:</b></td>
<td><b><B>User ID:</b></td>
<td><b><B>First Name:</b></td>
<td><b><B>Last Name:</b></td>
<td><b><B>Departments:</b></td>
<td><b><B>Status:</b></td>
<td><b><B>Record Number:</b></td>
</tr>
<%
mytime.connect();
ResultSet rs = mytime.viewUsers();
while (rs.next()) {
%>
<tr>
<td><%= rs.getString("fname"
</tr>
<%
}
%>
</table>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
</body>
</html>