|
public class Program
{
public static void Main(string[] args)
{
try
{
if (args.Length != 3)
{
ShowUsage();
return;
}
MailMessage mmMessage = new MailMessage();
mmMessage.To.Add(new MailAddress(args[2] as string));
mmMessage.From = new MailAddress(args[1] as string);
mmMessage.Subject = "TestMail";
mmMessage.Body = "This is a test";
SmtpClient sc = new SmtpClient(args[0] as string);
sc.Send(mmMessage);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine();
Console.Write("Press a key >");
Console.ReadKey();
}
}
private static void ShowUsage()
{
Console.WriteLine("Usage");
Console.WriteLine("TestMail [SmtpServer] [FromAddress] [ToAddress]");
}
}
Regards,
|
|
|
|
|
I don't have a conversion of the 'MailMessage' or 'MailAddress' types, or 'Console.ReadKey', but I have a conversion that should help a bit:
public class Program
{
public static void main(String[] args)
{
try
{
if (args.length != 3)
{
ShowUsage();
return;
}
MailMessage mmMessage = new MailMessage();
mmMessage.To.add(new MailAddress((String)((args[2] instanceof String) ? args[2] : null)));
mmMessage.From = new MailAddress((String)((args[1] instanceof String) ? args[1] : null));
mmMessage.Subject = "TestMail";
mmMessage.Body = "This is a test";
SmtpClient sc = new SmtpClient((String)((args[0] instanceof String) ? args[0] : null));
sc.Send(mmMessage);
}
catch (Throwable ex)
{
System.out.println(ex);
}
finally
{
System.out.println();
System.out.print("Press a key >");
Console.ReadKey();
}
}
private static void ShowUsage()
{
System.out.println("Usage");
System.out.println("TestMail [SmtpServer] [FromAddress] [ToAddress]");
}
}
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB
|
|
|
|
|
Hello,
This is a noob question but I wish to know how to connect to a Webservice that is created by ASP.net from NETBEANS 6.5. How can this be done?
|
|
|
|
|
hi all,
i m calling a vc++ exe from in java code using the Runtime.exec() function.
it gives the error
Debug Assertion Failed!
program: mantra.exe
File: fgets.c
Line: 60
Expression: str !=NULL
When the exe is run directly by dbl clicking it runs fine.
anybody help !!!!
don.
|
|
|
|
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class cmdExec {
public String run(String cmdLine) {
String line;
String output = "";
try {
Process p = Runtime.getRuntime().exec(cmdLine);
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output += (line + '\n');
}
input.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
return output;
}
}
dunno if that will help at all - but it ws useful for me when I couldnt run a prog from the cmd line
|
|
|
|
|
thanks for instant reply sir,
but my problem is its giving the error when i call the exe. I used the same type of code ie. exec() function. If i call some small exe it works, but when i call this one (its a huge exe with lots of supporting files) it fails. The error is debug assertion fail.
should i post this in MFC forum ?
don
|
|
|
|
|
I am not sure if this will help. But it worth a try. Please using aother overload of exec method:
exec(String command, String[] envp, File dir)
specify a correct dir parameter.
|
|
|
|
|
Thanks a lot deepnighttwo.
that worked. m happy. that had gven me many sleepless nights.
|
|
|
|
|
|
Please read carefully the eleven commandments [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hey Doofus!
No one here is going to do your homework for you. If you are so stupid that you can't even make a start at this then tell your teacher you want out!
As for
rajisweety wrote: rajesh.saimani@gmail.com
This will be picked up by every web-trawler looking for e-mails. Enjoy the spam!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
sorry...........it's ohk.
|
|
|
|
|
Absolutely! The following is the code that you need. Just copy and paste it into a java file (a text file with the extension .java):
import java.douche.bag;
for (int i=0; i < 1; i)
{
System.out.println("I'm a douche.bag who tries to get other people to do his homework for him");
}
Buddy - these forums aren't for you to try to sidestep your homework.
Did you really think anyone would?
|
|
|
|
|
|
First of all, it's not 'URGENT'. I don't have any urgent need to do it and I'm sure everyone else here will think so as well.
Secondly, was there any need to post the same thing twice? What purpose did it serve? Do you think that no-one is capable of clicking on the next post down?
No-one is write your program for you. It look's like a school assignment, which means that you are ment to learn how to do it. You're going to get nowhere in life if you pass off other peoples hard work as your own, it's just going to annoy people.
rajisweety wrote: need a program in java as soon as possible.....
I suggest that you pull you finger out and start writing it then.
rajisweety wrote: rajesh.saimani@gmail.com
Tehe, I can sign up to lots of naughty sites using your email and flood you indox with unwanted spam. I'm sure you don't want that.
ps. I think that you should have a read of a message I posted recently, Click[^]. Also, may I suggest Rent-A-Coder[^], if you feel that it is 'urgent'.
My failometer has shot off the end of the scale!
I seem to have misplaced my ban button.. no wait... found it!
|
|
|
|
|
The Query that I am executing is below:
select PRIMARY_KEY from NASTI_AUDIT_FIELD_LKUP nafl,NASTI_AUDIT na WHERE 0 = 0 AND nafl.DESIGNATED_UPDT_SCREEN_NAME = 'NPA-NXX-X MDN Range' AND nafl.FIELD_NAME = 'Category Code' and nafl.NASTI_AUDIT_FIELD_LKUP_ID = na.NASTI_AUDIT_FIELD_LKUP_ID
I have a method formatResults()in the DBAccessor.java file. The above query returns a value of PRIMARY_KEY = 9893834000 and getColumnType of ResultSetMetaData gives me the Integer instead of Numeric. Hence it's trying to cast as Integer and throwing an exception. But my question is why it's returning the type as Integer instead of Numeric. The above query works fine in TOAD. In the database the datatype of this field is NUMERIC. Can any one please help me to figure it out the issue?
|
|
|
|
|
The Query that I am executing is below:
select PRIMARY_KEY from NASTI_AUDIT_FIELD_LKUP nafl,NASTI_AUDIT na WHERE 0 = 0 AND nafl.DESIGNATED_UPDT_SCREEN_NAME = 'NPA-NXX-X MDN Range' AND nafl.FIELD_NAME = 'Category Code' and nafl.NASTI_AUDIT_FIELD_LKUP_ID = na.NASTI_AUDIT_FIELD_LKUP_ID
I have a method formatResults()in the DBAccessor.java file. The above query returns a value of PRIMARY_KEY = 9893834000 and getColumnType of ResultSetMetaData gives me the Integer instead of Numeric. Hence it's trying to cast as Integer and throwing an exception. But my question is why it's returning the type as Integer instead of Numeric. The above query works fine in TOAD. In the database the datatype of this field is NUMERIC. Can any one please help me to figure it out the issue?
private Vector formatResults(ResultSet results, boolean getDateAsString) throws OICException
{
m_logger.debug("Entered into formatResults()" );
Vector rowInfo = new Vector();
try
{
ResultSetMetaData rsmd = results.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
int rowCount = 0;
DateFormat formatShort = DateFormat.getDateInstance(DateFormat.SHORT);
while (results.next())
{
Hashtable rowVals = new Hashtable();
for (int i=1; i <= numberOfColumns; ++i)
{
String colName = rsmd.getColumnName(i);
m_logger.debug("colName : " + colName);
int resultType = rsmd.getColumnType(i);
m_logger.debug("resultType : " + resultType);
Object colValue;
if(results.getObject(i) != null)
{
m_logger.debug("results.getObject(i) : " + results.getObject(i));
switch(resultType)
{
case Types.DOUBLE:
case Types.INTEGER:
m_logger.debug("I am in INTEGER");
m_logger.debug("results.getInt(i) : " + results.getInt(i));
colValue = new Integer(results.getInt(i));
m_logger.debug("colValue : " + colValue);
break;
case Types.DECIMAL:
m_logger.debug("I am in DECIMAL");
colValue = new Integer(results.getInt(i));
m_logger.debug("colValue : " + colValue);
break;
case Types.FLOAT:
m_logger.debug("I am in FLOAT");
colValue = new Float(results.getFloat(i));
m_logger.debug("colValue : " + colValue);
break;
case Types.NUMERIC:
m_logger.debug("I am in NUMERIC");
m_logger.debug("results.getLong(i) : " + results.getLong(i));
colValue = new Long(results.getLong(i));
m_logger.debug("colValue : " + colValue);
break;
case Types.TIMESTAMP:
m_logger.debug("I am in TIMESTAMP");
if (getDateAsString)
colValue = formatShort.format(results.getDate(i));
else
colValue = results.getDate(i);
break;
case Types.CLOB:
m_logger.debug("I am in CLOB");
Clob tempClob = results.getClob(i);
colValue = tempClob.getSubString(1,(int)(tempClob.length()));
break;
default:
m_logger.debug("I am in default");
colValue = results.getString(i);
m_logger.debug("colValue : " + colValue);
break;
}
}
else
{
colValue = "";
}
if (colValue != null)
{
rowVals.put(colName, colValue);
}
}
rowInfo.insertElementAt(rowVals, rowCount);
++rowCount;
}
}
catch(SQLException e)
{
e.printStackTrace(System.out);
throw new OICException(e, e.toString() + "Exception in DBAccessor:formatResults \n");
}
return rowInfo;
}
|
|
|
|
|
Firstly, I admit that I don't know the answer.
But, may I suggest that you put your code in <pre></pre> tags, so that the formatting is preserved and it is easier to read.
And may I ask why you felt the need to post your message twice?
May I also suggest that you should consider tidying up your subject header.
My failometer has shot off the end of the scale!
I seem to have misplaced my ban button.. no wait... found it!
|
|
|
|
|
Hi,
I have a client written in java applet and it listens for responses on http: //localhost/CardPager.
Now, I have a server code written using jsp servlets and a webpage for a user
where I can write a message in a textbox and press the send button, the text message should go to the client.
1. Can someone tell me how do I go about writing this?
2. My next question is suppose I have many client applets running. Each of my clients have a unique ID to them. I want to send the message only to a set of IDs. How to do this.
I hope my questions were clear.
Thank you.
|
|
|
|
|
Hey,
I was hoping someone might be able to help me with some java script.
Im trying to create a button that you can click that will dim just the background with a dark but around 80% opacity 'layer'. Or perhaps a way to temporarily change the background altogether. Then when you press the button again, it goes back to normal (no 'layer'/original background).
I need this because ive got a really bright background on my site, but also have vids that ppl want to watch - and the contrast is a bit much... but i dont want to stop using or permanently dim the background. (to better understand what im looking for here is my site adrs: www.enchantedsun.blogspot.com)
ive seen posts here and there on the internet with dimmer code suggestions, but as far as i can find its all for a pop up - msg or image. And they generally start out dimmed instead of normal. Ive tried editing the code to get what i want, but i cant seem to get it to work at all. My knowledge of java is limited right now (i hope to improve), so please forgive me.
Thanks!
~EnchantedSun
|
|
|
|
|
Hi,
I have written a small code to access javascript function from a java applet.
My function fails at this point
JSObject win = JSObject.getWindow(this);
I do not understand what is the reason.It gives me following errors when i excute the program :
Exception in thread "main" java.lang.UnsatisfiedLinkError: initClass
at netscape.javascript.JSObject.initClass(Native Method)
at netscape.javascript.JSObject.<clinit>(JSObject.java:61)
at test.InJava4.start(InJava4.java:52)
at test.Main.main(Main.java:30)
Please have a look at my code written below and tell me if i have written anything wrong.Please do help me out. Thnx.
My java Applet code is written below :
import java.net.*;
import java.applet.*;
import netscape.javascript.*;
import netscape.javascript.JSException;
public class InJava extends java.applet.Applet
{
public void init()
{
try
{
System.out.println("hi i am in appltet");
String msg = "Hello from Java (using javascript alert)";
JSObject win = JSObject.getWindow(this);
win.call ("doAlert", null);
}
catch (Exception Ex)
{
System.out.println(Ex.toString());
}
}
public void start(){}
public void stop(){}
public void destroy(){}
}
My JavaScript is written below :
;
function doAlert(s) {
alert(s);
}
<applet code="InJava.class"
="" name="myApplet" mayscript
="" height="10" width="10">
|
|
|
|
|
I want a different popup on each row of JTable.
So I thought of setting the row on right click and then add popmenu to JTable.
The following code will help you'll to understand the problem...
private synchronized void HandlePopup(java.awt.event.MouseEvent evt) {
jTable1.setComponentPopupMenu(null);
if(evt.getButton()==MouseEvent.BUTTON3){
int y = evt.getY();
int row = Math.round(y / jTable1.getRowHeight());
jTable1.setRowSelectionInterval(row, row);
System.out.println("Row Selected = " + row);
jTable1.setComponentPopupMenu(popupMenu);
}
else jTable1.setComponentPopupMenu(null);
}
private void CreatePopup() {
popupMenu = new JPopupMenu("Title");
JMenuItem cutMenuItem = new JMenuItem("Cut");
popupMenu.add(cutMenuItem);
JMenuItem copyMenuItem = new JMenuItem("Copy");
popupMenu.add(copyMenuItem);
JMenuItem pasteMenuItem = new JMenuItem("Paste");
pasteMenuItem.setEnabled(false);
popupMenu.add(pasteMenuItem);
popupMenu.addSeparator();
JMenuItem findMenuItem = new JMenuItem("Find");
popupMenu.add(findMenuItem);
}
Here for the first right click the row gets selected....
then only the popup works and then there is no row selection.
the pop is always the same...coz new row gets never selected...
So how can I handle both popup with right selection...???
Please help me with this...
|
|
|
|
|
Where are you determining if the mouse event is a right click or not?
Also - where are you attaching your pop up menu listener?
Your question is pretty poorly explained: it makes it harder to help you.
|
|
|
|
|
I have a little snippet of code that writes a little text file locally by calling the script through Javascript on a web page. It works fine. Here is the example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Local File Create Script</title>
</head>
<body>
<script>
function WriteToFile()
{
try
{
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateTextFile("C:\\test.txt", true);
s.writeline("This is a test");
s.writeline("Oh Yea!!!!");
s.Close();
}
catch(err)
{
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
</script>
<input name="write_to_file" type="button" id="write_to_file" onClick="WriteToFile()" value="Click Here" />
</body>
</html>
Now , what I would like to do is create that file on another computer by ip address. Here is what I got so far:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Network File Create Script</title>
</head>
<body>
<script>
function WriteToFile()
{
try
{
var fso, sDir, s;
fso = new Server.CreateObject("Scripting.FileSystemObject");
sDir = fso.GetFolder("\\10.6.3.45\c$", true);
s = fso.CreateTextFile("\test.txt", true);
s.writeline("This is a test");
s.writeline("Oh Yea!!!!");
s.Close();
}
catch(err)
{
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
</script>
<input name="write_to_file" type="button" id="write_to_file" onClick="WriteToFile()" value="Click Here" />
</body>
</html>
Here is the error I am getting:
Error: Number:-2146823279 Description:'Server' is undefined
Can anyone help me?
modified on Thursday, June 4, 2009 6:27 PM
|
|
|
|
|
I think you were just over complicating it. You're getting that error because new Server.CreateObject... it's wondering what Server is. Just use the ip like a regular path. I tested it, and this worked for me.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Local File Create Script</title>
</head>
<body>
<script>
function WriteToFile()
{
try
{
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateTextFile("\\\\205.67.214.8\\c$\\test.txt", true);
s.writeline("This is a test");
s.writeline("Oh Yea!!!!");
s.Close();
}
catch(err)
{
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
</script>
<input name="write_to_file" type="button" id="write_to_file" onClick="WriteToFile()" value="Click Here" />
</body>
</html>
(i hope you don't mind, but i didn't know you could even save to a file from js until i read your post. I hope you don't mind but i'm going to add this code to my library, ^_^. I only got the solution by being bored and playing with what you provided.)
Friday, June 5, 2009 9:01 AM
|
|
|
|