Article View: borland.public.jbuilder.java.language
Article #252JAR File Error
From: vichet
Date: Wed, 06 Sep 2006 05:09
Date: Wed, 06 Sep 2006 05:09
101 lines
2764 bytes
2764 bytes
Dear All;
please help!
Let me explain you first about my problem
1- connectToMySqlJoke
------------------------------
import java.sql.*;
public class connectToMySqlJoke {
private String serverHost;
private String port;
private String userName;
private String password;
private String schema;
private Connection connection=null;
private Boolean connected;
public connectToMySqlJoke(){
this.serverHost="localhost";
this.port="3306";
this.userName="root";
this.password="123456";
this.schema="jokedb";
Connect();
}
public void Connect(){
String connStr = "";
try {
Class.forName("com.mysql.jdbc.Driver");
connStr="jdbc:mysql://"+ this.serverHost +":";
connStr+=this.port + "/" + this.schema;
connection =
DriverManager.getConnection(connStr,this.userName,this.password);
this.connected=true;
}
catch (SQLException e){
this.connected=false;
//System.out.println("Sql error");
}
catch (ClassNotFoundException e){
this.connected=false;
//System.out.println("jdbc driver not found!");
}
}
public Connection getConncetion() {
return connection;
}
public void closeConnection(){
try {
connection.close();
}
catch (Exception e){}
}
public Boolean IsConnected(){
return this.connected;
}
}
2- TestConnection
---------------------
public class TestConnection {
public static void main(String[] args) {
connectToMySqlJoke mycnt=new connectToMySqlJoke();
System.out.print(mycnt.IsConnected());
}
}
Yes, it works after i compile it and it returns TRUE. it connects.
But after i make JAR file. it do not work. i wonder why?
I make like this:
My mainClass file contain: Main-Class: TestConnection
jar cmf mainClass Test.jar *.class
then i run
java -jar Test.jar
it return false
help help
Technical Details
Message-ID:
<44fe57fa@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f74b3,aacdbf63813b8dc0,start X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit From: "vichet" <vichetchea@everyday.com.kh> Newsgroups: borland.public.jbuilder.java.language Subject: JAR File Error Date: Wed, 6 Sep 2006 12:09:07 +0700 Lines: 106 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.2663 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2757 NNTP-Posting-Host: 203.223.40.254 Message-ID: <44fe57fa@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1157519354 203.223.40.254 (5 Sep 2006 22:09:14 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail