JDBC removed...
This commit is contained in:
parent
28a5a43a47
commit
deb15e2733
@ -19,7 +19,6 @@
|
|||||||
package com.iluwatar.datamapper;
|
package com.iluwatar.datamapper;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ import org.apache.log4j.Logger;
|
|||||||
* database schema is always ignorant of the objects that use it.) Since it's a form of Mapper ,
|
* database schema is always ignorant of the objects that use it.) Since it's a form of Mapper ,
|
||||||
* Data Mapper itself is even unknown to the domain layer.
|
* Data Mapper itself is even unknown to the domain layer.
|
||||||
* <p>
|
* <p>
|
||||||
* The below example demonstrates basic CRUD operations: select, add, update, and delete.
|
* The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class App {
|
public final class App {
|
||||||
@ -75,24 +74,24 @@ public final class App {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
/* Don't couple any Data Mapper to java.sql.SQLException */
|
||||||
throw new DataMapperException("Following data source(" + args[0] + ") is not supported");
|
throw new DataMapperException("Following data mapping type(" + args[0] + ") is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create new student */
|
/* Create new student */
|
||||||
Student student = new Student(UUID.randomUUID(), 1, "Adam", 'A');
|
Student student = new Student(1, "Adam", 'A');
|
||||||
|
|
||||||
/* Add student in respectibe db */
|
/* Add student in respectibe db */
|
||||||
mapper.insert(student);
|
mapper.insert(student);
|
||||||
|
|
||||||
/* Find this student */
|
/* Find this student */
|
||||||
final Optional<Student> studentToBeFound = mapper.find(student.getGuId());
|
final Optional<Student> studentToBeFound = mapper.find(student.getStudentId());
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("App.main(), db find returned : " + studentToBeFound);
|
log.debug("App.main(), db find returned : " + studentToBeFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update existing student object */
|
/* Update existing student object */
|
||||||
student = new Student(student.getGuId(), 1, "AdamUpdated", 'A');
|
student = new Student(student.getStudentId(), "AdamUpdated", 'A');
|
||||||
|
|
||||||
/* Update student in respectibe db */
|
/* Update student in respectibe db */
|
||||||
mapper.update(student);
|
mapper.update(student);
|
||||||
|
@ -18,42 +18,35 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.datamapper;
|
package com.iluwatar.datamapper;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class Student implements Serializable {
|
public final class Student implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private UUID guid;
|
private int studentId;
|
||||||
private int studentID;
|
|
||||||
private String name;
|
private String name;
|
||||||
private char grade;
|
private char grade;
|
||||||
|
|
||||||
public Student() {
|
public Student() {
|
||||||
this.guid = UUID.randomUUID();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Student(final UUID guid, final int studentID, final String name, final char grade) {
|
public Student(final int studentId, final String name, final char grade) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.guid = guid;
|
this.studentId = studentId;
|
||||||
this.studentID = studentID;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.grade = grade;
|
this.grade = grade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Student(final UUID guid) {
|
|
||||||
this.guid = guid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int getStudentId() {
|
public final int getStudentId() {
|
||||||
return studentID;
|
return studentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setStudentId(final int studentID) {
|
public final void setStudentId(final int studentId) {
|
||||||
this.studentID = studentID;
|
this.studentId = studentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getName() {
|
public final String getName() {
|
||||||
@ -72,12 +65,39 @@ public final class Student implements Serializable {
|
|||||||
this.grade = grade;
|
this.grade = grade;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final UUID getGuId() {
|
@Override
|
||||||
return guid;
|
public boolean equals(final Object inputObject) {
|
||||||
|
|
||||||
|
boolean isEqual = false;
|
||||||
|
|
||||||
|
/* Check if both objects are same */
|
||||||
|
if (this == inputObject) {
|
||||||
|
|
||||||
|
isEqual = true;
|
||||||
|
}
|
||||||
|
/* Check if objects belong to same class */
|
||||||
|
else if (inputObject != null && getClass() == inputObject.getClass()) {
|
||||||
|
|
||||||
|
final Student student = (Student) inputObject;
|
||||||
|
|
||||||
|
/* If student id matched */
|
||||||
|
if (this.getStudentId() == student.getStudentId()) {
|
||||||
|
|
||||||
|
isEqual = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isEqual;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
/* Student id is assumed to be unique */
|
||||||
|
return this.getStudentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String toString() {
|
public final String toString() {
|
||||||
return "Student [guid=" + guid + ", studentID=" + studentID + ", name=" + name + ", grade=" + grade + "]";
|
return "Student [studentId=" + studentId + ", name=" + name + ", grade=" + grade + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,10 @@
|
|||||||
package com.iluwatar.datamapper;
|
package com.iluwatar.datamapper;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface StudentDataMapper {
|
public interface StudentDataMapper {
|
||||||
|
|
||||||
public Optional<Student> find(final UUID uniqueID) throws DataMapperException;
|
public Optional<Student> find(final int studentId);
|
||||||
|
|
||||||
public void insert(final Student student) throws DataMapperException;
|
public void insert(final Student student) throws DataMapperException;
|
||||||
|
|
||||||
|
@ -18,52 +18,25 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.datamapper;
|
package com.iluwatar.datamapper;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.util.List;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class StudentMySQLDataMapper implements StudentDataMapper {
|
public final class StudentMySQLDataMapper implements StudentDataMapper {
|
||||||
|
|
||||||
|
/* Note: Normally this would be in the form of an actual database */
|
||||||
|
private List<Student> students;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Optional<Student> find(final UUID uniqueID) throws DataMapperException {
|
public final Optional<Student> find(final int studentId) {
|
||||||
|
|
||||||
try {
|
/* Compare with existing students */
|
||||||
/* OracleDriver class cant be initilized directly */
|
for (final Student student : this.students) {
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
|
||||||
|
|
||||||
/* Create new connection */
|
/* Check if student is found */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/MySQL", "username", "password");
|
if (student.getStudentId() == studentId) {
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
|
||||||
final String statement = "SELECT `guid`, `grade`, `studentID`, `name` FROM `students` where `guid`=?";
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
|
||||||
|
|
||||||
/* Set unique id in sql statement */
|
|
||||||
dbStatement.setString(1, uniqueID.toString());
|
|
||||||
|
|
||||||
/* Execute the sql query */
|
|
||||||
final ResultSet rs = dbStatement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
|
|
||||||
/* Create new student */
|
|
||||||
final Student student = new Student(UUID.fromString(rs.getString("guid")));
|
|
||||||
|
|
||||||
/* Set all values from database in java object */
|
|
||||||
student.setName(rs.getString("name"));
|
|
||||||
student.setGrade(rs.getString("grade").charAt(0));
|
|
||||||
student.setStudentId(rs.getInt("studentID"));
|
|
||||||
|
|
||||||
return Optional.of(student);
|
return Optional.of(student);
|
||||||
}
|
}
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from MySQL data source.", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return empty value */
|
/* Return empty value */
|
||||||
@ -71,90 +44,54 @@ public final class StudentMySQLDataMapper implements StudentDataMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void update(final Student student) throws DataMapperException {
|
public final void update(final Student studentToBeUpdated) throws DataMapperException {
|
||||||
try {
|
|
||||||
|
|
||||||
/* OracleDriver class cant be initilized directly */
|
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
|
||||||
|
|
||||||
/* Create new connection */
|
/* Check with existing students */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/MySQL", "username", "password");
|
if (this.students.contains(studentToBeUpdated)) {
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
/* Get the index of student in list */
|
||||||
final String statement = "UPDATE `students` SET `grade`=?, `studentID`=?, `name`=? where `guid`=?";
|
final int index = this.students.indexOf(studentToBeUpdated);
|
||||||
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
/* Update the student in list */
|
||||||
|
this.students.set(index, studentToBeUpdated);
|
||||||
|
|
||||||
/* Set java object values in sql statement */
|
} else {
|
||||||
dbStatement.setString(1, Character.toString(student.getGrade()));
|
|
||||||
dbStatement.setInt(2, student.getStudentId());
|
|
||||||
dbStatement.setString(3, student.getName());
|
|
||||||
dbStatement.setString(4, student.getGuId().toString());
|
|
||||||
|
|
||||||
/* Execute the sql query */
|
/* Throw user error */
|
||||||
dbStatement.executeUpdate();
|
throw new DataMapperException("Student [" + studentToBeUpdated.getName() + "] is not found");
|
||||||
|
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from MySQL data source.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void insert(final Student student) throws DataMapperException {
|
public final void insert(final Student studentToBeInserted) throws DataMapperException {
|
||||||
try {
|
|
||||||
|
|
||||||
/* OracleDriver class cant be initilized directly */
|
/* Check with existing students */
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
if (!this.students.contains(studentToBeInserted)) {
|
||||||
|
|
||||||
/* Create new connection */
|
/* Add student in list */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/MySQL", "username", "password");
|
this.students.add(studentToBeInserted);
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
} else {
|
||||||
final String statement = "INSERT INTO `students` (`grade`, `studentID`, `name`, `guid`) VALUES (?, ?, ?, ?)";
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
|
||||||
|
|
||||||
/* Set java object values in sql statement */
|
/* Throw user error */
|
||||||
dbStatement.setString(1, Character.toString(student.getGrade()));
|
throw new DataMapperException("Student already [" + studentToBeInserted.getName() + "] exists");
|
||||||
dbStatement.setInt(2, student.getStudentId());
|
|
||||||
dbStatement.setString(3, student.getName());
|
|
||||||
dbStatement.setString(4, student.getGuId().toString());
|
|
||||||
|
|
||||||
/* Execute the sql query */
|
|
||||||
dbStatement.executeUpdate();
|
|
||||||
|
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from MySQL data source.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void delete(final Student student) throws DataMapperException {
|
public final void delete(final Student studentToBeDeleted) throws DataMapperException {
|
||||||
try {
|
|
||||||
|
|
||||||
/* OracleDriver class cant be initilized directly */
|
/* Check with existing students */
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
if (this.students.contains(studentToBeDeleted)) {
|
||||||
|
|
||||||
/* Create new connection */
|
/* Delete the student from list */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/MySQL", "username", "password");
|
this.students.remove(studentToBeDeleted);
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
} else {
|
||||||
final String statement = "DELETE FROM `students` where `guid`=?";
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
|
||||||
|
|
||||||
/* Set java object values in sql statement */
|
/* Throw user error */
|
||||||
dbStatement.setString(1, student.getGuId().toString());
|
throw new DataMapperException("Student [" + studentToBeDeleted.getName() + "] is not found");
|
||||||
|
|
||||||
/* Execute the sql query */
|
|
||||||
dbStatement.executeUpdate();
|
|
||||||
|
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from MySQL data source.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,52 +18,25 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.datamapper;
|
package com.iluwatar.datamapper;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.util.List;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class StudentOracleDataMapper implements StudentDataMapper {
|
public final class StudentOracleDataMapper implements StudentDataMapper {
|
||||||
|
|
||||||
|
/* Note: Normally this would be in the form of an actual database */
|
||||||
|
private List<Student> students;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Optional<Student> find(final UUID uniqueID) throws DataMapperException {
|
public final Optional<Student> find(final int studentId) {
|
||||||
|
|
||||||
try {
|
/* Compare with existing students */
|
||||||
/* OracleDriver class cant be initilized directly */
|
for (final Student student : this.students) {
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
|
||||||
|
|
||||||
/* Create new connection */
|
/* Check if student is found */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle", "username", "password");
|
if (student.getStudentId() == studentId) {
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
|
||||||
final String statement = "SELECT `guid`, `grade`, `studentID`, `name` FROM `students` where `guid`=?";
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
|
||||||
|
|
||||||
/* Set unique id in sql statement */
|
|
||||||
dbStatement.setString(1, uniqueID.toString());
|
|
||||||
|
|
||||||
/* Execute the sql query */
|
|
||||||
final ResultSet rs = dbStatement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
|
|
||||||
/* Create new student */
|
|
||||||
final Student student = new Student(UUID.fromString(rs.getString("guid")));
|
|
||||||
|
|
||||||
/* Set all values from database in java object */
|
|
||||||
student.setName(rs.getString("name"));
|
|
||||||
student.setGrade(rs.getString("grade").charAt(0));
|
|
||||||
student.setStudentId(rs.getInt("studentID"));
|
|
||||||
|
|
||||||
return Optional.of(student);
|
return Optional.of(student);
|
||||||
}
|
}
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from Oracle data source.", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return empty value */
|
/* Return empty value */
|
||||||
@ -71,90 +44,54 @@ public final class StudentOracleDataMapper implements StudentDataMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void update(final Student student) throws DataMapperException {
|
public final void update(final Student studentToBeUpdated) throws DataMapperException {
|
||||||
try {
|
|
||||||
|
|
||||||
/* OracleDriver class cant be initilized directly */
|
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
|
||||||
|
|
||||||
/* Create new connection */
|
/* Check with existing students */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle", "username", "password");
|
if (this.students.contains(studentToBeUpdated)) {
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
/* Get the index of student in list */
|
||||||
final String statement = "UPDATE `students` SET `grade`=?, `studentID`=?, `name`=? where `guid`=?";
|
final int index = this.students.indexOf(studentToBeUpdated);
|
||||||
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
/* Update the student in list */
|
||||||
|
this.students.set(index, studentToBeUpdated);
|
||||||
|
|
||||||
/* Set java object values in sql statement */
|
} else {
|
||||||
dbStatement.setString(1, Character.toString(student.getGrade()));
|
|
||||||
dbStatement.setInt(2, student.getStudentId());
|
|
||||||
dbStatement.setString(3, student.getName());
|
|
||||||
dbStatement.setString(4, student.getGuId().toString());
|
|
||||||
|
|
||||||
/* Execute the sql query */
|
/* Throw user error */
|
||||||
dbStatement.executeUpdate();
|
throw new DataMapperException("Student [" + studentToBeUpdated.getName() + "] is not found");
|
||||||
|
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from Oracle data source.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void insert(final Student student) throws DataMapperException {
|
public final void insert(final Student studentToBeInserted) throws DataMapperException {
|
||||||
try {
|
|
||||||
|
|
||||||
/* OracleDriver class cant be initilized directly */
|
/* Check with existing students */
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
if (!this.students.contains(studentToBeInserted)) {
|
||||||
|
|
||||||
/* Create new connection */
|
/* Add student in list */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle", "username", "password");
|
this.students.add(studentToBeInserted);
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
} else {
|
||||||
final String statement = "INSERT INTO `students` (`grade`, `studentID`, `name`, `guid`) VALUES (?, ?, ?, ?)";
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
|
||||||
|
|
||||||
/* Set java object values in sql statement */
|
/* Throw user error */
|
||||||
dbStatement.setString(1, Character.toString(student.getGrade()));
|
throw new DataMapperException("Student already [" + studentToBeInserted.getName() + "] exists");
|
||||||
dbStatement.setInt(2, student.getStudentId());
|
|
||||||
dbStatement.setString(3, student.getName());
|
|
||||||
dbStatement.setString(4, student.getGuId().toString());
|
|
||||||
|
|
||||||
/* Execute the sql query */
|
|
||||||
dbStatement.executeUpdate();
|
|
||||||
|
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from Oracle data source.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void delete(final Student student) throws DataMapperException {
|
public final void delete(final Student studentToBeDeleted) throws DataMapperException {
|
||||||
try {
|
|
||||||
|
|
||||||
/* OracleDriver class cant be initilized directly */
|
/* Check with existing students */
|
||||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
if (this.students.contains(studentToBeDeleted)) {
|
||||||
|
|
||||||
/* Create new connection */
|
/* Delete the student from list */
|
||||||
final Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle", "username", "password");
|
this.students.remove(studentToBeDeleted);
|
||||||
|
|
||||||
/* Create new Oracle compliant sql statement */
|
} else {
|
||||||
final String statement = "DELETE FROM `students` where `guid`=?";
|
|
||||||
final PreparedStatement dbStatement = connection.prepareStatement(statement);
|
|
||||||
|
|
||||||
/* Set java object values in sql statement */
|
/* Throw user error */
|
||||||
dbStatement.setString(1, student.getGuId().toString());
|
throw new DataMapperException("Student [" + studentToBeDeleted.getName() + "] is not found");
|
||||||
|
|
||||||
/* Execute the sql query */
|
|
||||||
dbStatement.executeUpdate();
|
|
||||||
|
|
||||||
} catch (final SQLException | ClassNotFoundException e) {
|
|
||||||
|
|
||||||
/* Don't couple any Data Mapper to java.sql.SQLException */
|
|
||||||
throw new DataMapperException("Error occured reading Students from Oracle data source.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user