Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jar file

Status
Not open for further replies.

keenanbr

Programmer
Oct 3, 2001
469
IE
I am new to java. I have written an application which works just fine but when I package it into a jar file it fails when trying to connect to the database(see below) with SQLException no suitable driver found for jdbc.oracle.thin......... Any help appreciated.

package as400;

import java.sql.*;
import oracle.sql.CLOB;
import java.io.*;
import java.util.*;

public class DBAccess
{
private static Connection connection;

public static void connect(String server, String database, String userName, String password)
{
connect(server, database, userName, password, "1521");
}

public static void connect(String server, String database, String userName, String password, String port)
{
registerOracleDriver();

try
{
String dbString = "jdbc:eek:racle:thin:mad:" + server + ":" + port + ":" + database;
connection = DriverManager.getConnection(dbString, userName, password);
}
catch (SQLException e)
{
e.printStackTrace();
}
}

private static void registerOracleDriver()
{
try
{
Class.forName("oracle.jdbc.OracleDriver");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
 
I have the manifest setup to run TestAs400UI, so at the command line i run

java -jar As400.jar

It runs until I enter my data and the application attempts to connect to the database.


Regards,
 
I guess you don't have the oracle jar in the classpath. How do you execute it when you say "it runs fine"?

Cheers,
Dian
 
The CLASSPATH is the same in buth cases. I am running from the same cmd window.

If I run java as400.TestAs400UI it works fine i.e. displays UI, allows me to enter data and retrieves data from the database.

If I run java -jar As400.jar it displays UI, allows me to enter data and then falls over with SQLException

Regards,
 
I'd try
Code:
java -jar As400.jar -classpath <path-to-oracle.jar>
or include it in the MANIFEST file


Cheers,
Dian
 
Same result. I will try including in the manifest.
 
I must be doing something really stupid but I can't figure it out.

If I delete the CLASSPATH env var.

java as400.TestAs400UI fails with SQLexception (as expected)
-----------------------------

if i run

java as400.TestAs400UI -classpath <exactly what was in CLASSPATH env var> it fails with SQLException (not as expected)
---------------------------

if i put back the CLASSPATH env var

java as400.TestAs400UI works fine.

 
I discovered what I was doing wrong. Should be

java -classpath <path to jar> as400.TestAs400UI

This works but still no luck with the jar.
 
Thanks for your help. I finally got it working by setting up classpath in the manifest. If you uses -jar the CLASSPATH env var is ignored.

classpath in manifest must be relative to jar and can't have C:\dir\dir or backward slashes

mainifest now reads....

Main-Class: as400.TestAs400UI
Class-Path: ../sqldeveloper-2.1.0.62.61-no-jre/sqldeveloper/jdbc/lib/ojdbc5.jar

 
You're totally rigth, classpath switches are ignores when executing a jar.

My bad

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top