import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Jdbc { String dbUrl = "jdbc:oracle:thin:@localhost:1521:wish"; String theUser = "scott"; String thePw = "tiger"; Connection connection = null; Statement statement; ResultSet set = null; public Jdbc() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); connection = DriverManager.getConnection(dbUrl, theUser, thePw); statement = connection.createStatement(); } public boolean executeUpdate(String sql) { try { statement.executeUpdate(sql); return true; } catch (SQLException e) { e.printStackTrace(); return false; } } public ResultSet executeQuery(String sql) throws SQLException { return statement.executeQuery(sql); } public void close() throws SQLException { set.close(); statement.close(); connection.close(); } }