Java connections
Java connections
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
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
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...
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
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...
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
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
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...
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....
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
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();
}
}
}
}
Does anyone have working code just to launch an email plz.
Thx
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...
You have a function embedded in a function. Is mail not maybe meant to be declared as a class?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).
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
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
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
hmm...
launches your mail client...
in a similar fashion:
will open the default editor/player based on file type and
will launch the default browser...
which JDK are you working in?
Code: Select all
java.awt.Desktop.getDesktop().mail();
in a similar fashion:
Code: Select all
java.awt.Desktop.getDesktop().open(File f);
//or
java.awt.Desktop.getDesktop().edit(File f);
Code: Select all
java.awt.Desktop.getDesktop().browse(URI u);
which JDK are you working in?
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.I used the javamail API It works as a full email client so it's overkill
Most people would sooner die than think; in fact, they do so - Bertrand Russel
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 ?
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 ?
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...
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?
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?
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...
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
e-mail:
note that the URI syntax permits chaining addresses...
open word 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.
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"));
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
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 ?
Any ideas on how I can get my program to open webmail ?
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...
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
- 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:my school uses a program called webmail for their email
java.awt.Desktop is a new addition, (JAVA 6SE). check your current version:Tiza wrote:I also found out that the .desktop thing doesnt work there cause i can't import the .awt.desktop thing...
"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
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
urgh... seriously consider getting them to update.... 1.5 and 1.6 are worlds apart.Tiza wrote:i think my school had 1.5
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
Ok i want print values from a databse but i get this random error for no reason
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);
}
}
import java.sql.*;CODE 1
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);
}
}
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...
import java.sql.*;CODE 2
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");
}
}
}
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...
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
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
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...
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
hi...
don;t have much time, but just glancing through:
1) You're re-initialising your connection object:
finally, be sure to use the wasNull() method provided in the ResultSet class:
will have a more detailed gander later...
don;t have much time, but just glancing through:
1) You're re-initialising your connection object:
also, try to reference columns by index, not label...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");
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...
}
Most people would sooner die than think; in fact, they do so - Bertrand Russel
OK i made a really basic mistake, i had a different name in my database
I downloaded Eclipse classic from the European mirror and my Eclipse works fine but i can't create visual classes... Any ideas?
I downloaded Eclipse classic from the European mirror and my Eclipse works fine but i can't create visual classes... Any ideas?
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...