Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Properties;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- public class DataBase {
- Connection con;
- PreparedStatement pst2;
- PreparedStatement pst;
- PreparedStatement pst3;
- java.sql.Statement stm;
- public DataBase() throws SQLException, ClassNotFoundException {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "");
- stm = con.createStatement();
- }
- void insert() throws SQLException {
- pst = con.prepareStatement("INSERT INTO `employee` (`Fname`, `Minit`, `Lname`, `Ssn`, `Bdate`, `Address`,"
- + " `Sex`, `Salary`, `Super_ssn`, `Dno`) VALUES ('alla', 'e', 'emad', '159442648', "
- + "'2019-11-14', 'dubai', 'F', '5000', '123456789', '1');");
- }
- void update() throws SQLException {
- pst2 = con.prepareStatement("UPDATE `employee` SET `Fname` = 'Salwa' WHERE `Fname` = 'alla';");
- }
- void delete() throws SQLException {
- pst3 = con.prepareStatement("DELETE FROM `employee` WHERE SSN ='159442648';");
- }
- String select() throws SQLException {
- String s = "";
- ResultSet rs = stm.executeQuery("select * from `employee`");
- while (rs.next()) {
- s += (rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + "\n"); //getInt()
- }
- return s;
- }
- void mailSent(){
- final String username = "username@gmail.com";
- final String password = "password";
- Properties prop = new Properties();
- prop.put("mail.smtp.host", "smtp.gmail.com");
- prop.put("mail.smtp.port", "465");
- prop.put("mail.smtp.auth", "true");
- prop.put("mail.smtp.socketFactory.port", "465");
- prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
- Session session;
- session = Session.getInstance(prop,
- new javax.mail.Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("from@gmail.com"));
- message.setRecipients(
- Message.RecipientType.TO,
- InternetAddress.parse("to_username_a@gmail.com, to_username_b@yahoo.com")
- );
- message.setSubject("Testing Mail");
- message.setText("Email Sent!");
- Transport.send(message);
- System.out.println("Done");
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement