You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
3.0 KiB
65 lines
3.0 KiB
package com.example.dao;
|
|
|
|
import java.io.IOException;
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
|
|
import com.example.bean.StudentProfileBean;
|
|
import com.example.utility.Connect;
|
|
|
|
public class StudentProfileDAO {
|
|
Connect connect = new Connect();
|
|
|
|
public void create(String name, int age, String location, String interest, String studentID)
|
|
throws SQLException, IOException {
|
|
try (Connection connection = connect.databaseConnect()) {
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(
|
|
"INSERT INTO studentProfile (name, age, location, interest, studentID) VALUES (?,?,?,?,?)")) {
|
|
preparedStatement.setObject(1, name);
|
|
preparedStatement.setObject(2, age);
|
|
preparedStatement.setObject(3, location);
|
|
preparedStatement.setObject(4, interest);
|
|
preparedStatement.setObject(5, studentID);
|
|
preparedStatement.executeUpdate();
|
|
}
|
|
}
|
|
}
|
|
|
|
public StudentProfileBean getProfile(String studentID) throws SQLException, IOException {
|
|
try (Connection connection = connect.databaseConnect()) {
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(
|
|
"SELECT * FROM studentProfile WHERE studentID=?")) {
|
|
preparedStatement.setObject(1, studentID);
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
if (resultSet.next()) {
|
|
StudentProfileBean studentProfileBean = new StudentProfileBean();
|
|
studentProfileBean.setId(resultSet.getInt("id"));
|
|
studentProfileBean.setName(resultSet.getString("name"));
|
|
studentProfileBean.setAge(resultSet.getInt("age"));
|
|
studentProfileBean.setLocation(resultSet.getString("location"));
|
|
studentProfileBean.setInterest(resultSet.getString("interest"));
|
|
studentProfileBean.setStudentID(resultSet.getString("studentID"));
|
|
return studentProfileBean;
|
|
} else
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void update(String name, int age, String location, String interest, String studentID)
|
|
throws SQLException, IOException {
|
|
try (Connection connection = connect.databaseConnect()) {
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(
|
|
"UPDATE studentProfile SET name = ?, age = ?, location = ?, interest = ? WHERE studentID = ? ")) {
|
|
preparedStatement.setObject(1, name);
|
|
preparedStatement.setObject(2, age);
|
|
preparedStatement.setObject(3, location);
|
|
preparedStatement.setObject(4, interest);
|
|
preparedStatement.setObject(5, studentID);
|
|
preparedStatement.executeUpdate();
|
|
}
|
|
}
|
|
}
|
|
} |