Java connections

Get help on programming - C++, Java, Delphi, etc.
Post Reply
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Java connections

Post by Tiza »

Yo everyone

I am doing a java project where i use GUI and connect to a database and all that. NOw i need help with teh following please:

The code so you can connect to Microsoft word so it either opens a existing .doc or it just reads the information into the console.

Secondly i want to create a button so when u press it, it opens up email so you can sent a message to a specific address.

Thanks
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

as for default app launching, i would suggest using the static methods provided in java.awt.Desktop..

the word doc issue is a little trickier, (especially with office 2007), as the format is mickeysoft's homegrown tripe. the 2007 versions are their version of the open standard xml, (naturally, their interpretation of "open standards" is very microsoft-centirc...). if you're not into building your own parser/regex/document combination, your best bet would be to hunt around places like sourceforge in the hopes that someone has already covered this one for you...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

I am only using office 2003... Cause the schools computers are useless. I am not so much worried about the word doc cause i can just read it out of notepad if i have 2. Its the email thing that concerns me
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

In which case the Desktop class is what you're after.

The methods provided will launch whichever app is the system default
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

O yes I see it now, Thanks
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

Ok so you have to import Desktop but i dont know if my version of Java has it.

I am really lost on this mail thing....

Code: Select all

	
         public void mail(URI uri) {

 			
         private void onLaunchMail(java.awt.event.ActionEvent evt) {
             String mailTo = txtMailTo.getText();
             URI uriMailTo = null;
             try {
                 if (mailTo.length() > 0) {
                     uriMailTo = new URI("mailto", mailTo, null);
                     desktop.mail(uriMailTo);
                 } else {
                     desktop.mail();
                 }
             }
             catch(IOException ioe) {
                 ioe.printStackTrace();
             }
             catch(URISyntaxException use) {
                 use.printStackTrace();
             }
           
         }	
}
}

I got that but i dont have a clue if it's right cause i get an error with the line = private void onLaunchMail(java.awt.event.ActionEvent evt).


Does anyone have working code just to launch an email plz.

Thx
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

I got that but i dont have a clue if it's right cause i get an error with the line = private void onLaunchMail(java.awt.event.ActionEvent evt).
You have a function embedded in a function. Is mail not maybe meant to be declared as a class?

I used the javamail API. It works as a full email client so it's overkill but you might have to use it if you don't come right.

You can get it from the Sun website.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

hmm...

Code: Select all

java.awt.Desktop.getDesktop().mail();
launches your mail client...

in a similar fashion:

Code: Select all

java.awt.Desktop.getDesktop().open(File f);
//or
java.awt.Desktop.getDesktop().edit(File f);
will open the default editor/player based on file type and

Code: Select all

java.awt.Desktop.getDesktop().browse(URI u);
will launch the default browser...

which JDK are you working in?
I used the javamail API It works as a full email client so it's overkill
quite true. SMTP only, but it works well.. the drawback being that it is not packaged with the JVM, so requires that it be part and parcel of any app using it, or packaged with the installer. If you're hunting for some mechanism to automate alerts, etc, then it's well worth the effort getting to grips with it.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

Ok thanks a lot...

how do i define the address in the email client,so the user does not havve to type it in?

is it mailto:john@abc.com ?
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

That would be correct.
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

Ok i dont know if i am retarded or what but it keeps giving me and error and there is no way to fix it...

WHere do i put this line of code i have tried everything :?

soz

ok and how does

java.awt.Desktop.getDesktop().open(File f);

work ?

So it can open word or what?
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

e-mail:

Code: Select all

java.awt.Desktop.getDesktop().mail(new java.net.URI("mailto:anonymous@anon.com"));
//or
java.awt.Desktop.getDesktop().mail(new java.net.URI("mailto:anonymous@anon.com;infamous@infamy.com"));
note that the URI syntax permits chaining addresses...

open word doc:

Code: Select all

java.awt.Desktop.getDesktop().open(new java.io.File("C:/Path_to_Doc/WordDoc.doc"));

if you're going to be making successive calls to Desktop, consider retaining a reference to an instance. The open() method will perform the default action using the default editor/player. if the target file were a movie, it would launch whichever app is currently pegged as being the default media player.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

Sweet thanks dog
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

only a pleasure... :wink:

shout if you don't come right...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

Ok a slight problem, my school uses a program called webmail for their email, i think it uses the Office 2003 server or something. I also found out that the .desktop thing doesnt work there cause i can't import the .awt.desktop thing...

Any ideas on how I can get my program to open webmail ?
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

Tiza wrote:my school uses a program called webmail for their email
- which remains a problem. as it's web based, the most you can do is pass in the mail url which will launch the browser, (there is no launchable client). if you have access to the pop information, you may be able to use hex's suggestion and grab the SMTP extension, (a little more fiddly, but it works well).
Tiza wrote:I also found out that the .desktop thing doesnt work there cause i can't import the .awt.desktop thing...
java.awt.Desktop is a new addition, (JAVA 6SE). check your current version:

"Start"->"Run"->
"cmd">>Enter
"java -version">>Enter

the reported version should be 1.6.X_XX...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

Ok well i think my school had 1.5, isnt there any code that laucnhes the default email system???
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

Tiza wrote:i think my school had 1.5
urgh... seriously consider getting them to update.... 1.5 and 1.6 are worlds apart.

if you have no joy, the most stable approach would be to grab a copy of the JDIC. while it is possible to launch native apps from within the JVM, it is frowned upon, as most implementations ignore the console IO, which can lead to issues down the line.

The JDIC project was a precursor for some of the implementations in JAVA 6.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

Ok i want print values from a databse but i get this random error for no reason :(

CODE 1
import java.sql.*;
import java.io.*;
public class AnimalShelter {

protected String type;
protected String size;
protected String name;
protected int food;

public AnimalShelter(String type, String size, String name, int food) {
super();
// TODO Auto-generated constructor stub
this.type = type;
this.size = size;
this.name = name;
this.food = food;
}

public int getFood() {
return food;
}

public void setFood(int food) {
this.food = food;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSize() {
return size;
}

public void setSize(String size) {
this.size = size;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String Spaces(String x){

for(int i = x.length(); i < 20; i ++ ){


x = x + "";
}
return x;

}

public void PrintDetails(){

String a = Spaces(type);
String b = Spaces(size);
String c = Spaces (name);


System.out.println(a+b+c+food);


}



}
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

CODE 2
import java.sql.*;
import java.io.*;



public class AnimalManager {

AnimalShelter [] Z = new AnimalShelter [100];
public Connection c;
int point =0 ;

public void con()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException c)
{System.out.println("unable to load database driver");}
try
{ c=DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Animals.mdb");
System.out.println("Conection done");
}
catch(Exception e)
{System.out.println("No Connection to dataBASE");}

}


public void fromDatabase() throws SQLException{
con();
Statement s = c.createStatement();
point = 0;
ResultSet rs = s.executeQuery("SELECT * FROM Moo");

while(rs.next()){
con();
String type = rs.getString("Type");
String size = rs.getString("Size");
String name = rs.getString("Name");
int food = rs.getInt("Food");
System.out.println("___");

Z [point] = new AnimalShelter(type,size,name,food);
point ++;

}

s.close();

}

public void Print(){

for(int i = 0; i < 20; i ++){

Z.PrintDetails();
System.out.print("D");

}



}

}
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

CODE 3 this is the main app that runs

import java.sql.*;
import java.io.*;
public class AnimalMain {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

AnimalManager mm = new AnimalManager();


mm.Print();

}

}

Code: Select all

Error
Exception in thread "main" java.lang.NullPointerException
at AnimalManager.Print(AnimalManager.java:55)
at AnimalMain.main(AnimalMain.java:14)

Its is with the Array that is suppose to print and the class Print that i call in the main app.


Please help so confused
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

hi...

don;t have much time, but just glancing through:

1) You're re-initialising your connection object:
public void fromDatabase() throws SQLException{
con()
Statement s = c.createStatement();
point = 0;
ResultSet rs = s.executeQuery("SELECT * FROM Moo");

while(rs.next()){
con();
String type = rs.getString("Type");
also, try to reference columns by index, not label...

finally, be sure to use the wasNull() method provided in the ResultSet class:

Code: Select all

while(rs.next()){
String type = rs.getString("Type"); 
type = rs.wasNull()?"":type.trim();
etc...
}
will have a more detailed gander later...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

OK i got the con thing but have done this many times and now all of a sudden it does not work.

Thanks :)
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
Tiza
Registered User
Posts: 1486
Joined: 01 Dec 2004, 02:00
Location: At your window
Contact:

Post by Tiza »

OK i made a really basic mistake, i had a different name in my database :oops:

I downloaded Eclipse classic from the European mirror and my Eclipse works fine but i can't create visual classes... Any ideas?
Image
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

Tiza wrote:i can't create visual classes... Any ideas?
?

could you specify what you mean by "visual" classes?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Post Reply