Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exercise2Lib_8140058;
- import java.net.URL;
- import java.io.*;
- import java.sql.*;
- import java.util.ArrayList;
- import java.util.List;
- public class DB_EX2_8140058 {
- private String errorMessages= "";
- private Connection con = null;
- private PreparedStatement stmt = null;
- private String theQuery = "SELECT * FROM emploee_8xxxxxx WHERE salary >= ? AND salary <= ?;";
- private ResultSet rs = null;
- /**
- * Provides a connection with the Database Server. Initializes JDBC driver
- * for MySQL. Establishes a connection with the Database Server.
- *
- * @throws SQLException
- * (with the appropriate message) if any driver or connection
- * error occured.
- */
- public void open() throws SQLException{
- //Load the JDBC driver
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- } catch (Exception e1) {
- errorMessages = "MySQL Driver error: <br>" +e1.getMessage();
- throw new SQLException(errorMessages);
- }
- //Register driver and establish the connection
- try {
- con = DriverManager.getConnection(
- "jdbc:mysql://195.251.249.131:3306/ismgroup25","ismgroup25","zdsp$4");
- } catch (Exception e2) {
- errorMessages = "Could not establish connection with the Database Server: <br>"
- +e2.getMessage();
- con = null;
- throw new SQLException(errorMessages);
- }
- }
- /**
- * Ends the connection with the database Server. Closes all Statements and
- * ResultSets. Finally, closes the connection with the Database Server.
- *
- * @throws SQLException
- * (with the appropriate message) if any error occured.
- */
- public void close() throws SQLException {
- try {
- if (stmt != null)
- stmt.close();
- if (rs != null)
- rs.close();
- if (con != null)
- con.close();
- } catch (Exception e3) {
- errorMessages = "Could not close connection with the Database Server: <br>"
- + e3.getMessage();
- throw new SQLException(errorMessages);
- }
- }
- /**
- * Checks if from and to are valide.
- *
- *@return list, with Emploee objects
- */
- public List<Emploee> findEmploeesBySalaryRange(double from, double to) throws Exception {
- if (con == null) {
- errorMessages = "You must establish a connection first!";
- } else {
- List<Emploee> emploeList = new ArrayList<Emploee>();
- try {
- stmt = con.prepareStatement(theQuery);
- //replacing the first ? with from and the second ? with to
- stmt.setDouble(1, from);
- stmt.setDouble(2, to);
- //execute query
- rs = stmt.executeQuery();
- //Add new Emploees
- while (rs.next()) {
- emploeList.add(new Emploee());
- }
- return emploeList;
- } catch (Exception e4) {
- errorMessages = "Error while executing SELECT query: <br>" + e4.getMessage();
- throw new SQLException(errorMessages);
- }
- }
- }
- }
- COMPILATION ERROR:
- C:\Users\JIM\Desktop\exercise2Lib_8140058\DB_EX2_8140058.java:84: error: cannot find symbol
- public List<Emploee> findEmploeesBySalaryRange(double from, double to) throws Exception {
- ^
- symbol: class Emploee
- location: class DB_EX2_8140058
- C:\Users\JIM\Desktop\exercise2Lib_8140058\DB_EX2_8140058.java:90: error: cannot find symbol
- List<Emploee> emploeList = new ArrayList<Emploee>();
- ^
- symbol: class Emploee
- location: class DB_EX2_8140058
- C:\Users\JIM\Desktop\exercise2Lib_8140058\DB_EX2_8140058.java:90: error: cannot find symbol
- List<Emploee> emploeList = new ArrayList<Emploee>();
- ^
- symbol: class Emploee
- location: class DB_EX2_8140058
- C:\Users\JIM\Desktop\exercise2Lib_8140058\DB_EX2_8140058.java:104: error: cannot find symbol
- emploeList.add(new Emploee());
- ^
- symbol: class Emploee
- location: class DB_EX2_8140058
- 4 errors
- Tool completed with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement