🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.language
2 messages
2 total messages Started by vichet Wed, 06 Sep 2006 05:09
JAR File Error
#252
Author: vichet
Date: Wed, 06 Sep 2006 05:09
101 lines
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
Re: JAR File Error
#253
Author: Paul Furbacher [TeamB]
Date: Wed, 06 Sep 2006 13:55
69 lines
3022 bytes
vichet wrote:

> [...]
> 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

My guess is that you need to include the MySQL JDBC driver
JAR in the classpath.  The IDE does this for you when you
add it as a required library.  However, when you JAR up
your little application, the required driver classes are
not included.  (Note that you are instantiating the driver
class by reflection.  This has consequences as to what is
included in the JAR which the Archiver makes.

To do this, change the manifest option of the Archiver node so
that on the "Manifest" page in the Properties dialog.

1. Set it to "Create manifest and save to ...."

2. Rebuild the archive.

3. Open the Application Archive Properties dialog again, and
select option "Override ..." and if necessary use the "..."
browse button to navigate to the src/META-INF folder in your
project and select the manifest file.  (This shouldn't be
necessary, but just in case.)

4. Edit the manifest.mf file; insert

Manifest-Version: 1.0
Class-Path: [path-to]/mysql-connector-java-3.1.6-bin.jar
Main-Class: org.pf.teambanswers.DynamicDriverLoader


Here's a reference you should read; it applies to some other
situation but applies to your case (Google +manifest +classpath
for more info):
 
http://www.iona.com/support/docs/e2a/asp/5.1/j2ee/petstore/tutorial4.html

Read Step 2 thoroughly.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads