//Hi,
//I want to make an application that sends email; the email need to be taken from an oracle database, I had make the email code and it is working succseeful and also I made the coonection to the database in the next class which is also working successfully, but the problem I couldn't get the email from the database in this class
//This is ther class where it sends an email

import com.sun.crypto.provider.RSACipher;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.io.*;

public class conn extends CDB {

//public class sendMail {
String d_email = "sofien.fkih@gmail.com",
d_password = "",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "@gmail.com",
m_subject = "Testing",
m_text = "Hey, this is the testing email.";


public conn()
{
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

SecurityManager security = System.getSecurityManager();

try
{
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);

MimeMessage msg = new MimeMessage(session);
msg.setText(m_text);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
Transport.send(msg);
}
catch (Exception mex)
{
mex.printStackTrace();
}
}

public static void main1(String[] args)
{
conn blah = new conn();

}

private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(d_email, d_password);
}
}

}

//this is the class where it connects to database

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.io.*;


public class Main {

    public static void main(String[] args) {

   // conn con1 = new conn();
       try
    {
    String host = "jdbc:oracle:thin:@ 127.0.0.1:1521:XE";
    String uName = "hr";
    String password="";
    Connection con = DriverManager.getConnection( host, uName, password );
    Statement stmt = con.createStatement( );
    String SQL = "SELECT * FROM students";
    ResultSet rs = stmt.executeQuery( SQL );
   rs.next();

int    id_col = rs.getInt("STUDENT_ID");
String first_name = rs.getString("First_Name");
String last_name = rs.getString("Last_Name");

//.out.println( id_col + " " + first_name + " " + last_name  );


    if (id_col==400)
    {
 // String mail=first_name+con1.m_to;

        try{{
          // conn blah = new conn();

    Process p=Runtime.getRuntime().exec("cmd /c start http:www."+first_name+".com");

    // those code is made to open a web page, and messages is the attribute of the table sms



    // all those code were made 18,19/07/2012 by sofien fki and mohammed ahmed

}


    }

    catch(IOException e1){System.out.println(e1);



}

    }


    }
    catch ( SQLException err )
    {
System.out.println( err.getMessage( ) );



}





    }



}

Forgive me if I am wrong, but judging by this post, and your other post http://www.daniweb.com/software-development/java/threads/428659/getting-values-from-on-public-void-to-another-class I find it hard to believe that you "made" all that code yourself.
You are jumping into quite complex areas (email, database) when there are catastrophic gaps in your knowledge of Java fundamentals (eg variable scope). It may be frustrating, but you will get further sooner if you take a little time now to go back to basics and learn your Java one step at a time. There are many people here who will help you along a properly planned path.

commented: thanks about your worries but please what I want is the correct java code to correct the task +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.