I have been writing in Java for a few months now; however, I still consider myself fairly new to it because all of my experience in Java has been writing Beans. I have reached the point in developing the project that I am on where I have to write a small and simple Java program in order to try to debug a portion of the Bean that I'm working on. I can't do this from within a Bean because I need to rely on console debugging output.
I thought that I would be able to throw this together relatively quickly, but I can't get this to run due to an error of:
dgetsman@linuxdamon:~/src/java$ java -cp . Main
Exception in thread "main" java.lang.NoSuchMethodError: main
at this point.
The code is simple and I am fairly confident that it is fine except for main() not being found. I would appreciate any assistance, comments, or pointers to relevant material about this issue. Here is the code:
Code:
import java.util.Date;
import java.sql.*;
public class Main {
private static final String dbdriver="com.mysql.jdbc.Driver";
private static final String dburl="jdbc:mysql://localhost/amitimesheets";
private static final String dbuser="root";
private static final String dbpw="nevahgonnagetit";
private java.util.Date startDate, endDate;
private int month, year, patient, location;
public Main() {
}
public void main(String[] args) {
//set everything here to avoid having to mess with user I/O at this
//point
month = 7; year = 2008; patient = 10047; location = 1024;
startDate = new java.util.Date(year, month, 1, 0, 0, 0);
endDate = new java.util.Date(year, month, 30, 23, 59, 59);
System.out.println("\n\nmonth: " + month + "\nyear: " + year + "\n");
System.out.println("\n\nstartDate: " + startDate + "\nendDate: " +
endDate + "\n");
try {
Class.forName(dbdriver);
Connection con = DriverManager.getConnection(dburl, dbuser, dbpw);
String sql = "SELECT id,starttime,endtime FROM punches WHERE" +
" pateitn = ? AND location = ? AND deleted = 0 AND " +
"starttime >= ? AND starttime <= ?";
System.out.println("\n\nsql: " + sql + "\n");
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, patient);
stmt.setInt(2, location);
stmt.setDate(3, new java.sql.Date(startDate.getTime()));
stmt.setDate(4, new java.sql.Date(endDate.getTime()));
System.out.println("\n\nstmt: " + stmt + "\n");
ResultSet rs = stmt.executeQuery();
//let's see what we've got in there
System.out.println("\n\n" + rs + "\n");
} catch (Exception exception) {
System.out.println("\n\nGot an error:\n\t" + exception +
"\n");
}
}
}
Thanks in advance!
-Damon Getsman