This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
How to include database libraries?!
- From: melko at gmx dot at
- To: java at gcc dot gnu dot org
- Date: Wed, 5 Jan 2005 09:03:00 +0100 (MET)
- Subject: How to include database libraries?!
Hallo!
I have a big problem that I cannot solve since 2 weeks!
Now the problem is: I want to make an .exe out of Java-Code with this bundle
gcc40-20040925.tar.bz2 from http://www.thisiscool.com! It includes in the
gcjlib.jar the swt-files that I also need so it is easier to compile! The
gcjlib.jar is version 4.0.0 !
Now I can make an .exe-file and it works fine, but if I want to get a
connection it says for example
com.ibm....Driver not found in [file:.\,core:/]
and then the program crashes down! In the Source-Code I search for the
Driver with following function:
Class.forName(klass);
And this all works fine with eclipse where I included the database-jar-files
like libraries!
Now I tried several ways to compile it! I tried to make a reference in the
source-code to it so it can be included, I make a-files out of the
database.jar and so on, but nothing worked! I have also tried with a
ForceInclude.java file that includes the reference!
So I make an example-code with only one database-driver to test on it and
this I want to give to you so you can help me easier:
This is the connection.java file:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class connection{
/**
* I tried here to make a reference to the driver, and it asks, when I'm
* compiling after the source, so I put the classpath to SQLBaseJDBC.jar
* and it could compile but didn't work!
*/
//jdbc.gupta.sqlbase.SqlbaseDriver dummyRef;
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("jdbc.gupta.sqlbase.SqlbaseDriver").newInstance();
con =
DriverManager.getConnection("jdbc:sqlbase://192.168.172.212:2160/database","sysadm",
"sysadm");
if(!con.isClosed())
System.out.println("Successfully connected to SQLBase");
} catch(Exception e) {
System.out.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {
System.out.println("SQLException: " + e.getMessage());
}
}
}
}
This is the ForceInclude.java file:
public class ForceInclude {
private static final Class class1 =
jdbc.gupta.sqlbase.SqlbaseDriver.class;
ForceInclude() {
}
}
This are now several ways I tried to compile:
way 1:
@echo off
SETLOCAL
echo make library...
gcj -shared SQLBaseJDBC.jar -o libSQLBaseJDBC.a
echo make object...
gcj -c --classpath=libSQLBaseJDBC.jar connection.java
echo Compiliing exe...
gcj --main=connection connection.o -o connection
echo.
echo Finished!
pause
way 2:
@echo off
SETLOCAL
set prompt=?
PATH C:\gcc\bin;C:\gcc\i686-pc-mingw32\bin;%PATH%
set MAIN=connection
echo make class-files...
gcj -C -fCLASSPATH=bin;src; -d bin src\connection.java
gcj -C -fCLASSPATH=include\SQLBaseJDBC.jar;bin;src; -d bin
src\ForceInclude.java
echo make jar...
cd bin
jar cf %MAIN%.jar *.class
move %MAIN%.jar ..\include
cd ..
echo make object-files...
gcj --classpath=obj;bin; -c src\connection.java -o obj\connection.o
gcj --classpath=include\SQLBaseJDBC.jar;obj;bin; -c src\ForceInclude.java -o
obj\ForceInclude.o
echo Compiliing exe...
gcj --main=%MAIN% --classpath= -s -o %MAIN%.exe obj\*.o include\*.a
echo.
echo Finish!
pause
way 3:
@echo off
SETLOCAL
echo Compiling exe...
gcj --main=connection --classpath=SQLBaseJDBC.jar -shared SQLBaseJDBC.jar
*.java -o connection
echo.
echo Finish!
pause
So there are other ways that I also tried but without success!! I hope you
can help me!
The best way it were to make the libraries dynamical, that means that I can
add database.jar files afterworks and it can search for it...
I have also made an jar file out of the connection.java with the
manifest-file in which I say
Class-Path: SQLBaseJDBC.jar
Main-Class: connection
And it works perfect!! I must put the SQLBaseJDBC.jar only with the
connection.jar together!!
Thank you very much for your time, that you will spend on it!!
nice greetings from cold austria!
--
+++ GMX - die erste Adresse für Mail, Message, More +++
1 GB Mailbox bereits in GMX FreeMail http://www.gmx.net/de/go/mail