Joe Angott

Greenhorn
+ Follow
since Oct 13, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joe Angott

The demo runs fine. It finds the SMTP server just fine. When I use the same code in my app the Transport trys to use "localhost", port 25. In both I set the props the same way. Anyone with an idea? Here's the demo:
import java.lang.Thread.*;
import java.util.*;
import java.text.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class msgsendsample {
static String msgText = "How's this for a return address?";
public static void main(String[] args) {

String to = "joseph.angott@mail.com";
String from = "justanotherperson";
String host = "xxx.xxx.xxx.xxx";
boolean debug = true;
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host);

Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
for(int v =0 ; v < 5 ; v++ ){
try {
// create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Sending you an anonymous email.");
msg.setSentDate(new Date());
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(msgText);
Transport.send(msg);
} catch (MessagingException mex) {
System.out.println("\n--Exception handling in msgsendsample.java");
mex.printStackTrace();
System.out.println();
Exception ex = mex;
do {
if (ex instanceof SendFailedException) {
SendFailedException sfex = (SendFailedException)ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null) {
System.out.println(" ** Invalid Addresses");
if (invalid != null) {
for (int i = 0; i < invalid.length; i++)
System.out.println(" " + invalid[i]);
}
}
Address[] validUnsent = sfex.getValidUnsentAddresses();
if (validUnsent != null) {
System.out.println(" ** ValidUnsent Addresses");
if (validUnsent != null) {
for (int i = 0; i < validUnsent.length; i++)
System.out.println(" "+validUnsent[i]);
}
}
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null) {
System.out.println(" ** ValidSent Addresses");
if (validSent != null) {
for (int i = 0; i < validSent.length; i++)
System.out.println(" "+validSent[i]);
}
}
}
System.out.println();
if (ex instanceof MessagingException)
ex = ((MessagingException)ex).getNextException();
else
ex = null;
} while (ex != null);
}
try{
Thread.sleep(12000);
}catch(Exception e){
}
}
}
private static void usage() {
System.out.println("usage: java msgsendsample <to> <from> <smtp> true|false");
}
}

***************************************************************
And my app which is not functioning:
***************************************************************
package com.lsi.cendant.mailengine;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;
import java.util.*;
import javax.activation.*;
import com.lsi.cendant.objects.*;
public class Mailer {
protected static Message prepareHeader(SendMailObj sendMailObj)throws IOException, AddressException,MessagingException {

Properties props = new Properties();
String host = sendMailObj.getSmtpHost();
System.out.println (host);
props.put("mail.smtp.host", host);

Session session = Session.getDefaultInstance(props,null);
session.setDebug(true);
System.out.println ("Props is : " + props.toString());
Message msg = new MimeMessage(session);
msg.setText("I hope I get this.");


int number = 0;
for (int j = 0 ; j < sendMailObj.getToAddr().length ; j++){
if (sendMailObj.getToAddr()[j] == null)
break;
number = j + 1;
}
System.out.println("Getting ready to add the TO Addr's : " + number);
InternetAddress toAddr[] = new InternetAddress[number];
String [] toAddresses = sendMailObj.getToAddr();
for (int i = 0 ; i < number ; i++){
toAddr [i] = new InternetAddress(toAddresses[i]);
System.out.println("Added : " + toAddresses[i]);
}
msg.addRecipients(Message.RecipientType.TO,toAddr);
System.out.println("I have added the TO Addr's");
for (int j = 0 ; j < sendMailObj.getFromAddr().length ; j++){
if (sendMailObj.getFromAddr()[j] == null)
break;
number = j + 1;
}
System.out.println("Getting ready to add the FROM Addr's : " + number);
InternetAddress fromAddr[] = new InternetAddress[number];
String [] fromAddresses = sendMailObj.getFromAddr();
for (int i = 0 ; i < number ; i++){
fromAddr [i] = new InternetAddress(fromAddresses[i]);
System.out.println("Added : " + fromAddresses[i]);
}
try{
msg.addFrom(fromAddr);
}catch (Exception e){
// InternetAddress errorFromAddr [] = {new InternetAddress("EmailerProg@mail.com")};
// msg.addFrom(errorFromAddr);
}
System.out.println("I have added the FROM Addr's");
msg.setSubject(sendMailObj.getSubject());
msg.setSentDate(new Date());

System.out.println("RECIP : " + msg.getRecipients(Message.RecipientType.TO).length);
msg.setText(sendMailObj.getMessage());

return msg;
}
public static void sendMail(SendMailObj sendMailObj)throws IOException, AddressException, MessagingException {
Message msg = null;
try{
msg = prepareHeader (sendMailObj);
Transport.send(msg);
} catch (MessagingException mex) {
System.out.println("\n--Exception handling in Mailer.java");
mex.printStackTrace();
System.out.println();
Exception ex = mex;
do {
if (ex instanceof SendFailedException) {
SendFailedException sfex = (SendFailedException)ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null) {
System.out.println(" ** Invalid Addresses");
if (invalid != null) {
for (int i = 0; i < invalid.length; i++)
System.out.println(" " + invalid[i]);
}
}
Address[] validUnsent = sfex.getValidUnsentAddresses();
if (validUnsent != null) {
System.out.println(" ** ValidUnsent Addresses");
if (validUnsent != null) {
for (int i = 0; i < validUnsent.length; i++)
System.out.println(" "+validUnsent[i]);
}
}
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null) {
System.out.println(" ** ValidSent Addresses");
if (validSent != null) {
for (int i = 0; i < validSent.length; i++)
System.out.println(" "+validSent[i]);
}
}
}
System.out.println();
if (ex instanceof MessagingException)
ex = ((MessagingException)ex).getNextException();
else
ex = null;
} while (ex != null);
}
try{
Thread.sleep(12000);
}catch(Exception e){
}
}
}

The sleep statements are there for debuging purposes in my IDE. else the dos window disappears to fast for me to read.
22 years ago
The demo runs fine. It finds the SMTP server just fine. When I use the same code in my app the Transport trys to use "localhost", port 25. In both I set the props the same way. Anyone with an idea? Here's the demo:
import java.lang.Thread.*;
import java.util.*;
import java.text.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class msgsendsample {
static String msgText = "How's this for a return address?";
public static void main(String[] args) {

String to = "joseph.angott@mail.com";
String from = "justanotherperson";
String host = "xxx.xxx.xxx.xxx";
boolean debug = true;
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host);

Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
for(int v =0 ; v < 5 ; v++ ){
try {
// create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Sending you an anonymous email.");
msg.setSentDate(new Date());
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(msgText);
Transport.send(msg);
} catch (MessagingException mex) {
System.out.println("\n--Exception handling in msgsendsample.java");
mex.printStackTrace();
System.out.println();
Exception ex = mex;
do {
if (ex instanceof SendFailedException) {
SendFailedException sfex = (SendFailedException)ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null) {
System.out.println(" ** Invalid Addresses");
if (invalid != null) {
for (int i = 0; i < invalid.length; i++)
System.out.println(" " + invalid[i]);
}
}
Address[] validUnsent = sfex.getValidUnsentAddresses();
if (validUnsent != null) {
System.out.println(" ** ValidUnsent Addresses");
if (validUnsent != null) {
for (int i = 0; i < validUnsent.length; i++)
System.out.println(" "+validUnsent[i]);
}
}
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null) {
System.out.println(" ** ValidSent Addresses");
if (validSent != null) {
for (int i = 0; i < validSent.length; i++)
System.out.println(" "+validSent[i]);
}
}
}
System.out.println();
if (ex instanceof MessagingException)
ex = ((MessagingException)ex).getNextException();
else
ex = null;
} while (ex != null);
}
try{
Thread.sleep(12000);
}catch(Exception e){
}
}
}
private static void usage() {
System.out.println("usage: java msgsendsample <to> <from> <smtp> true|false");
}
}
And my app which is not functioning:
package com.lsi.cendant.mailengine;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;
import java.util.*;
import javax.activation.*;
import com.lsi.cendant.objects.*;
public class Mailer {
protected static Message prepareHeader(SendMailObj sendMailObj)throws IOException, AddressException,MessagingException {

Properties props = new Properties();
String host = sendMailObj.getSmtpHost();
System.out.println (host);
props.put("mail.smtp.host", host);

Session session = Session.getDefaultInstance(props,null);
session.setDebug(true);
System.out.println ("Props is : " + props.toString());
Message msg = new MimeMessage(session);

InternetAddress errorFromAddr = new InternetAddress("joseph.angott@mail.com");
msg.addRecipient(Message.RecipientType.TO,errorFromAddr);
msg.setText("I hope I get this.");


int number = 0;
for (int j = 0 ; j < sendMailObj.getToAddr().length ; j++){
if (sendMailObj.getToAddr()[j] == null)
break;
number = j + 1;
}
System.out.println("Getting ready to add the TO Addr's : " + number);
InternetAddress toAddr[] = new InternetAddress[number];
String [] toAddresses = sendMailObj.getToAddr();
for (int i = 0 ; i < number ; i++){
toAddr [i] = new InternetAddress(toAddresses[i]);
System.out.println("Added : " + toAddresses[i]);
}
msg.addRecipients(Message.RecipientType.TO,toAddr);
System.out.println("I have added the TO Addr's");
for (int j = 0 ; j < sendMailObj.getFromAddr().length ; j++){
if (sendMailObj.getFromAddr()[j] == null)
break;
number = j + 1;
}
System.out.println("Getting ready to add the FROM Addr's : " + number);
InternetAddress fromAddr[] = new InternetAddress[number];
String [] fromAddresses = sendMailObj.getFromAddr();
for (int i = 0 ; i < number ; i++){
fromAddr [i] = new InternetAddress(fromAddresses[i]);
System.out.println("Added : " + fromAddresses[i]);
}
try{
msg.addFrom(fromAddr);
}catch (Exception e){
// InternetAddress errorFromAddr [] = {new InternetAddress("EmailerProg@mail.com")};
// msg.addFrom(errorFromAddr);
}
System.out.println("I have added the FROM Addr's");
msg.setSubject(sendMailObj.getSubject());
msg.setSentDate(new Date());

System.out.println("RECIP : " + msg.getRecipients(Message.RecipientType.TO).length);
msg.setText(sendMailObj.getMessage());

return msg;
}
public static void sendMail(SendMailObj sendMailObj)throws IOException, AddressException, MessagingException {
Message msg = null;
try{
msg = prepareHeader (sendMailObj);
Transport.send(msg);
} catch (MessagingException mex) {
System.out.println("\n--Exception handling in Mailer.java");
mex.printStackTrace();
System.out.println();
Exception ex = mex;
do {
if (ex instanceof SendFailedException) {
SendFailedException sfex = (SendFailedException)ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null) {
System.out.println(" ** Invalid Addresses");
if (invalid != null) {
for (int i = 0; i < invalid.length; i++)
System.out.println(" " + invalid[i]);
}
}
Address[] validUnsent = sfex.getValidUnsentAddresses();
if (validUnsent != null) {
System.out.println(" ** ValidUnsent Addresses");
if (validUnsent != null) {
for (int i = 0; i < validUnsent.length; i++)
System.out.println(" "+validUnsent[i]);
}
}
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null) {
System.out.println(" ** ValidSent Addresses");
if (validSent != null) {
for (int i = 0; i < validSent.length; i++)
System.out.println(" "+validSent[i]);
}
}
}
System.out.println();
if (ex instanceof MessagingException)
ex = ((MessagingException)ex).getNextException();
else
ex = null;
} while (ex != null);
}
try{
Thread.sleep(12000);
}catch(Exception e){
}
}
}

The sleep statements are there for debuging purposes in my IDE. else the dos window disappears to fast for me to read.
22 years ago
Kind of already got there and yes, using jni was just the ticket to ease my woes. Thanks much for the help! : )
22 years ago
I need to call a c++ program with arguments and be able to accept values back. How is this possible? Is it possible without going through CORBA?
23 years ago
Well I did some more extensive research and found this example (shown in part) from OTN, part of Oracle's online documentation.

try {

// If resultset is open, close it.
if (m_resultSet != null)
m_resultSet.close();

// Prepare a Callable Statement, to make a call the PLSQL function demo_refcursor.getRefCursor, and obtain the returned REFCURSOR
CallableStatement l_call =
m_connection.prepareCall("{? = call " + "demo_refcursor.getRefCursor }");

// set the Out Parameter type to be of type CURSOR
l_call.registerOutParameter(1, OracleTypes.CURSOR);
l_call.execute(); // Execute the statement

// Cast the returned parameter, (defined as type, OracleTypes.CURSOR) to a JDBC result-set. setFirstFive displays the first five rows of the returned REFCURSOR
m_resultSet = (ResultSet)l_call.getObject(1);

// Display the next five records from the newly opened resultset
displayNextFive();
m_GUI.m_nextRecord.setEnabled(true);
// Enable the "Next Five Records" button
} catch (SQLException ex) {
// Trap SQL errors
m_GUI.putStatus("Error running package demo_refcursor:");
m_GUI.appendStatus(ex.toString());
}

That's the guts of the Oracle Example, not too bad considering the lack of examples in most of Oracle's database reference material. Now here is the end result of my and other's research, and the answer to my own question. I hope it can help someone else.
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*; // comes from Oracle's classes1.2.zip
try {
CallableStatement retriveOrderStatusCall = conn.prepareCall("{? = call Order_Object.query_status_object(?) }");
retriveOrderStatusCall.setString(2, orderId);
retriveOrderStatusCall.registerOutParameter(1,OracleTypes.CURSOR);
retriveOrderStatusCall.execute();
retriveOrderStatusData =(ResultSet)retriveOrderStatusCall.getObject(1);

while(rs.next()){
System.out.print("Orderid "+rs.getString(1)+ " ");
System.out.print("Product "+rs.getString(2).trim()+ " ");
System.out.println("Status "+rs.getString(3).trim()+ " ");

}
There's the skinny, I hope this helps someone with a similar delima. If you were searching for the answer to help me, I appreciate the effort.
AOL IM LSIJAVAJOE.
[This message has been edited by Joe Angott (edited March 06, 2001).]
Ok, here's the skinny...
I have an Oracle stored function in a package that I call feeding it a single parameter. This is done using a callable statement. It then sends me back multiple rows of multiple columns of data.
Question #1: How do I define my out parameter portion of my call so that it is understood by the JDBC that I will be getting back a rowset?
Question #2: Once I get back my mountain of data, how do I go about parsing out the fields in each row? I think I might have a grasp on this one, but would like to know for sure. I think if I go through the result set and parse based on an index corisponding to the position of the field in that row it will give me my desired results.
I know this is probably not an easy one, but I would love for someone to prove me wrong.
Thanks,
Joe
AIM user id LSIJAVAJOE
You could also use the java code in your jsp to test (if lenth > 0 or !null) for the presence of data and the enclose the HTML display portion pertinent to the data in curly braces. This way the code in the table tags only gets seen by the browser when the test is true.
23 years ago