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.
62 lines
2.8 KiB
62 lines
2.8 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.EntrepriseProfileBean;
|
|
import com.example.utility.Connect;
|
|
|
|
public class EntrepriseProfileDAO {
|
|
Connect connect = new Connect();
|
|
|
|
public void create(String name, String overview, String companyID, String contactEmail) throws SQLException, IOException {
|
|
try (Connection connection = connect.databaseConnect()) {
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(
|
|
"INSERT INTO entrepriseProfile (name, overview, companyID, contactEmail) VALUES (?,?,?,?)")) {
|
|
preparedStatement.setObject(1, name);
|
|
preparedStatement.setObject(2, overview);
|
|
preparedStatement.setObject(3, companyID);
|
|
preparedStatement.setObject(4, contactEmail);
|
|
preparedStatement.executeUpdate();
|
|
}
|
|
}
|
|
}
|
|
|
|
public EntrepriseProfileBean getProfile(String companyID) throws SQLException, IOException {
|
|
try (Connection connection = connect.databaseConnect()) {
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(
|
|
"SELECT * FROM entrepriseProfile WHERE companyID=?")) {
|
|
preparedStatement.setObject(1, companyID);
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
if (resultSet.next()) {
|
|
EntrepriseProfileBean enterpriseProfileBean = new EntrepriseProfileBean();
|
|
enterpriseProfileBean.setId(resultSet.getInt("id"));
|
|
enterpriseProfileBean.setName(resultSet.getString("name"));
|
|
enterpriseProfileBean.setOverview(resultSet.getString("overview"));
|
|
enterpriseProfileBean.setCompanyID(resultSet.getString("companyID"));
|
|
enterpriseProfileBean.setContactEmail(resultSet.getString("contactEmail"));
|
|
return enterpriseProfileBean;
|
|
} else
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void update(String name, String overview, String companyID, String contactEmail)
|
|
throws SQLException, IOException {
|
|
try (Connection connection = connect.databaseConnect()) {
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(
|
|
"UPDATE entrepriseProfile SET name = ?, overview = ?, contactEmail = ? WHERE companyID = ? ")) {
|
|
preparedStatement.setObject(1, name);
|
|
preparedStatement.setObject(2, overview);
|
|
preparedStatement.setObject(3, contactEmail);
|
|
preparedStatement.setObject(4, companyID);
|
|
preparedStatement.executeUpdate();
|
|
}
|
|
}
|
|
}
|
|
}
|