package Pimms;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Payroll {
String dbURL = "jdbc:mysql://127.0.0.1/JSP_DB1?user=root&password=";
String dbDriver = "com.mysql.jdbc.Driver";
String query = "";
int r = 0;
private Connection dbCon;
public Payroll(){
super();
}
public boolean connect() throws ClassNotFoundException,SQLException
{ Class.forName(dbDriver);
dbCon = DriverManager.getConnection(dbURL);
return true;
}
public void close() throws SQLException
{ dbCon.close();
}
public ResultSet execSQL(String sql) throws SQLException
{ Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return (r == null) ? null : r;
}
public int updateSQL(String sql) throws SQLException
{ Statement s = dbCon.createStatement();
r = s.executeUpdate(sql);
return r;
}
public String getTimeIn(int emp_id, String date) throws SQLException
{ String time = "NONE";
query = "SELECT time FROM ATTENDANCE WHERE inout=1 AND emp_id="+emp_id+" AND date='"+date+"'";
// THIS IS WHERE MY PROBLEM LIES.
// USING THE CODE BELOW, I CAN CONNECT TO MY DB WITHOUT ANY PROBLEMS
// BUT IF U LOOK AT THE UPPER PORTION OF MY CODE, YOU WILL SEE METHODS
// NAMED connect(), execSQL(), updateSQL()
// I CREATED THESE 3 METHODS SO I WOULDN'T HAVE TO DECLARE THE dbCon
// (AMONG OTHER THINGS), the statement, the resulset OVER AND OVER AGAIN.
// BUT IF I PUT this: dbCon.connect();
// THIS ERROR APPEARS : interface java.sql.Connection
// please help... i would like to use as much java beans as possible
try
{ Class.forName(dbDriver).newInstance();
dbCon = DriverManager.getConnection(dbURL);
Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(query);
if(r.next())
time = r.getString("time");
r.close();
dbCon.close();
}catch(Exception e)
{ e.printStackTrace(); }
return time;
}
}