Problems with jdbc and .jar files.

I am having a problem with connecting to my database when running my .jar file as an executable.
It connects correctly when I use the java command in command prompt and it also runs correctly when using my IDE.
Is there something that needs to be added to the manifest or in the code it self inorder for the program to find the JDBC driver correctly?

This is the error message that I get:
java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at AboutFrame2$Connect.getConnection(AboutFrame2.java:109)
at AboutFrame2$Connect.displayDbProperties(AboutFrame2.java:127)
at AboutFrame2.<init>(AboutFrame2.java:72)
at MainStartFile2.main(MainStartFile2.java:7)
Error Trace in getConnection() : net.sourceforge.jtds.jdbc.Driver
Error: No active Connection
I think that it is because it cannot find the driver. I am going to add the path to the manifest and see if that works thank you for all the help.

Similar Messages

  • Problems with ClassLoader and Jar-Files

    1. I'm not good in englisch (writing).
    2. I have the problem, that i want to load a object from an application in Jar-File A out of the Jar-File B. I set the CLASSPATH for B with System.setProperty("java.class.path", <ClassPath>); . Then i tried to get the Class-object from a class of B. I do it with getClass().getForName("package.Name");.
    But everytime i get a ClassNotFoundException. Where is the Error? Or how can i load a class out of a Jar-File and get an instance? I hope you can help me..
    Tobain

    The error is that classes are loaded from the classpath as it existed when the program started. Changing the system property that was copied from the classpath has no effect, as you have seen. I have heard that you can write your own ClassLoader if you want to load classes from arbitrary locations, but I do not know how to do that myself.

  • Problem with Preview and PSD files - random gray square

    Hi guys, hope you can help...
    I've got a problem with Preview and PSD files.
    If I open in Preview both an original jpg straight from my reflex and the photoshop version of the same picture, the psd file presents a gray square (of what it seems unrendered image) in a random area of the photo (sometimes in the center.). The square is quite big...
    If I zoom in or zoom out it disappears...if I scroll to another photo and then back to the psd, the square it's there again...sometimes in a different position.
    I've tried the same psd on my older iMac with leopard...and got no problem at all.
    I suspect it got something to do with my Ati...
    (this is the second iMac 27...the first went back for gray banding on the lcd screen and flickering and yellow tinge........)
    Thanks for your help.
    DAve.

    maybe I'm onto something...
    I've just found out that opening Preview in 32bit mode (instead of default 64bit) works flawlessly with any psd files. If I switch back to 64bit mode, Preview is much faster but the gray square comes back...
    It seems like the i7 is much faster than the Ati....
    Any more realistic ideas?

  • Problem with JDBC and Tomcat

    I don't know where the problem originate, the only thing in my memory is that the program worked very well on my PC yesterday, but today, without even slightest change, it doesn't work anymore. As to debug it, I simplified the codes to the least, but it still refuse to work. I was beaten down by this problem totally, and cannot make out any solution for it, so, I come here, hoping to find a warrior to kill this damned bug for me.
    My program is a Servlet, but for the purpose of debugging, I have recode it to an Application/Servlet. When run as a application, I can get the result expected, but as a Servlet, :-(, maybe you should see it by yourself. My server software is Tomcat 4.1.15, and the JDK version is 1.4.0. To excute this program, you should add Data Source "Test" to ODBC.
    ///////////////////////code begins/////////////////////////
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class Ex extends HttpServlet
         int ErrorType = 0;
         String err = new String("");
         public static void main(String args[]) throws Exception{
              Ex cEx = new Ex();
              cEx.init();     
              System.out.println(cEx.ErrorType);     
         public void init() {
              String url = "jdbc:odbc:Test";
              ErrorType = 3;     //passed
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              } catch (ClassNotFoundException e) {
                   e.printStackTrace();
                   ErrorType = 1; //trapped in Class.forName
              try{
                   Connection c = DriverManager.getConnection(url);
              } catch (SQLException e) {
                   e.printStackTrace();
                   ErrorType = 2; //trapped in DriverManager.getConnection
                   err = e.getMessage();
         public void service(HttpServletRequest req, HttpServletResponse res)
                   throws IOException {
              res.setContentType("text/html; charset=GB2312");
              PrintWriter out = res.getWriter();
              out.println("Success " + "<p>" + ErrorType + "<p>" +err);
              out.close();
    //////////////////////////code ends///////////////////////////////
    The result from the Servlet tell me that the problem occurred within the connection process, I don't know who should be responsible to this - Tomcat or JDBC?

    If you could print the exception that you got then that would help :) In the mean time, I could make a guess. It is unlikely that your application server (in this case, Tomcat) is blocking connections from your servlet. So the problem is either with JDBC directly or with the underlying datasource. It seems unlikely that it is JDBC given that you have stated that the code has not changed and it works in application form.
    My guess would be that you are coming up against some sort of security constraint (eg: your DBMS is letting you log in from one IP but not another?, your Java plug-in security policy is disallowing the connection?). It's hard to say.
    But if it works as an application but not via a servlet then you could try putting this in your java.policy file, which is located in the directory where your plug-ins are installed (eg: "C:\Program Files\Java\<version>\lib\security\") on Windows systems;
    permission java.net.SocketPermission "bend xp:1099", "listen,connect,accept";
    Try that, see if it works :)
    Ben

  • Problem with Java and Zip Files

    Hello there everyone. I have a problem with trying to zip up directories with empty folders in them. They zip fine with my code, but according to winzip, the number of files in the archive is incorrect. It's supposed to have a total of 288 files in it, but when it's zipped up, it only says 284. I mention specifically the "empty directories" note because the zipping works fine without empty folders.
    Below is the code for the zip method:
    public static void zip(File[] list, File zipfile, File zipRoot)
         throws IOException {
          if (!zipfile.exists()) {
                   zipfile.createNewFile();
              else if (!zipfile.isFile()) {
                   throw new IOException("The zip file, " + zipfile.getAbsolutePath()
                             + " is not a file.");
              if (list.length == 0) {
                  LOG.error("The list of files to zip up is empty.");
              for (int i = 0; i < list.length; i++) {
                   if (!list.exists()) {
                        throw new IOException("The file or directory, " + list[i].getAbsolutePath()
                                  + " does not exist.");
              FileOutputStream fos = new FileOutputStream(zipfile);
              ZipOutputStream zos = new ZipOutputStream(fos);
              for (int i = 0; i < list.length; i++) {
                   if (LOG.isDebugEnabled())
                        LOG.debug(i + ": " + list[i].getName());
                   String entryName = getRelativeName(list[i], zipRoot);
                   if (list[i].isDirectory()){
                        if (list[i].listFiles().length == 0){
                             ZipEntry entry = new ZipEntry(entryName + "/");
                             zos.putNextEntry(entry);
                   else {
                        ZipEntry ze = new ZipEntry(entryName);
                        zos.putNextEntry(ze);
                        byte[] buffer = new byte[8096];
                        FileInputStream fis = new FileInputStream(list[i]);
                        int read = 0;
                        read = fis.read(buffer);
                        if (LOG.isDebugEnabled())
                        LOG.debug("\tFound " + read + " bytes.");
                        if (read == -1){
                             //empty file, but add it for preservation.
                             //zos.write(buffer,0,0);
                        while (read != -1) {
                             zos.write(buffer, 0, read);
                             read = fis.read(buffer);
                        fis.close();
                        zos.closeEntry();
              zos.close();
    The files look like they're there, but I need the system to be able to determine the number correctly. 
    Here's the interesting thing:  It zips the files, and then when I use the size() method for zip files in java, it says 284 files.  But when I unzip, it says 288 again.  It's like there's files missing when compressed, but when decompressed, they return.  Note that the files are actually there.  If I open the archive in a third party app such as Winzip AND Winrar AND IZarc, they all show 288 files.  Any idea what would make the number of files appear incorrectly in a zip file when zipped by java with the code above?  Thanks in advance.
    - Chris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I figured out the problem. When zipping files in windows using winzip, it doesn't explicitly count folders as a "file/folder" as a file in itself. It will create the folders for files to go in, but the folder itself will not be 'counted' when you query the info of the file itself. You have more control of the zip file in java, and can count the folder as a file or not.

  • Problems with creation of JAR file

    Hi!
    I can't succeed in creating a JAR file for my application.
    I've followed the guide at http://java.sun.com/docs/books/tutorial/deployment/jar/basicsindex.html
    but apparently im doing something wrong....
    I've tried doing an extra Manifest file aswell as "Setting an Entry Point with the JAR Tool" as written in the guide. noen with success however :(
    I always get the error "Could not find the main class. Program will exit." from the JVM when I try to run my JAR file.
    Structure of my program:
    C:\searchpath\moresearchpath\projectname\src\
    inside src\ there are 3 packages called; "graphic", "client" and "server".
    I want to make a JAR file from the files in the "server" package. The "server" package consists of these following 4 files(and nothing more); "ClientHandler.java", "TestServer.java", "ServerModel.java", "ServerController.java".
    "TestServer.java" is my main class!
    This is an example of a command I've done in order to try to make a JAR file:
    "C:\searchPathToWhereJavaIsInstalled\jdk1.6.0\bin\jar cvfe sgwserver.jar server.TestServer server\*"
    This doesn't generate any error. However when I try to start the .jar I get following message "Could not find the main class. Program will exit."
    I've also tried creating manifest file manually but without success (with UTF-8 encoding and not double .txt ending on file)
    This is how the "Manifest.txt" file has looked when I've tried making one:
    Main-Class: server.TestServer
    I have used Netbeans 5.5 and Java SE 6 for development
    What am I doing wrong? Please help me :(

    If I try to run the one generated from Netbeans I get the following error message: "Failed to load Main-Class manifest attribute from C:\searchpath\moresearchPath\projectName\dist\projectName.jar"
    The thing is I need 2 JAR files, one that contains the files in the "server" package and one that has all other files. The other one is an applet and the files in "server" package are a standalone application.
    How do I get the standalone application's JAR file to work?

  • Problem with addition of jar file to DC

    Hi WDers,
    I have a DC of type WD.
    I'm trying to add com.sap.security.api.jar file to this component so that I can get IUser and work on it.
    I have added this security jar file as an External jar file to the DC. But whenever I try to DC->Build, the jar entry is going away. So the Build is failing.
    Can you kindly let me know why this is happening?
    Or is there any other way to add a jar file so that I can use the IUser interface in my view?
    Thanks in Advance
    RK

    Hello,
    Add the Standard DC "com.sap.security.api.sda" from the SAP-JEE. This ahould solve the problem.
    To do that follow the steps:
    1. Go to the "DC Metadata" option available under the DC.
    2. Go to "Used DCs" and choose "Add used DCs" from the context menu which appears on a right click at the Used Dcs option.
    3.Select "com.sap.security.api.sda" under SAP-JEE and choose finish.
    4. Build the DC to gain access to the IUser and other related classes.
    Bala.

  • Problem with using external jar file

    Hi
    I was using mail.jar library for swing application to send and receive emails. It just works perfect when I run with netbeans. But when I run the executable jar file at dist folder it runs but mail related functions doesn't work.What should I do now to make it work with mail features outside netbeans.
    thanks
    vinay
    Edited by: 899657 on Dec 24, 2011 5:07 AM

    899657 wrote:
    No. Because I am running the jar file which is created by netbeansNetbeans creates a 'dist' directory in which it puts your jar and a "dist/lib' directory in which it puts the dependent jars that are added to the project using 'project right mouse click'->Properties->Libraries. I would expect to see this 'dist/lib' directory contain mail.jar and activation.jar and any other jars that your jar needs. Within your program jar's manifest I would expect to see the Class-Path attribute have relative reference these jars ( lib/mail.jar lib/activation.jar ) and for the Main-Class attribute define your main class.
    Given this setup then you should be able to just type -
    java -jar yourjar.jarto run your program.

  • Problems with JMF and audio files.

    Sofware:
    Java Version 1.5.0_03
    JMF Version 2.1.1e
    Windows XP SP2
    I have a application that consists of 2 parts. The first is an editor for creating exercises, like multiple-choice, matching and so on. The second part is a &#8220;client&#8221;, used to solve the exercises. The client uses Java Webstart.
    When I include audio clips in the exercises they play just fine using the client, but in the editor program I just get a clicking sound, and then the application stops responding.
    The strange part is that the editor and client use the exact same code to playback audio clips.
    The old version of the editor (developed for Java 1.3.x) works just fine under Java 1.3.x, but when the same byte-code is launched under Java 1.5 I get the same problem (clicking sound and then the application stops responding).
    Any suggestions?

    When installing JMF, two new packages are stored in the jre\lib\ext folder : jmf.jar and sound.jar.
    Sound.jar contains the same api that are in the packages sound.midi and sound sampled contained in jre.
    Maybe these new api are an improved version but i noticed some trouble playing sound and i delete sound.jar file, now it works fine.
    Try this, maybe you had the same problem.

  • Problems with Manifest building jar file

    Hello all,
    i try to deploy my application in a jar file. I also have some libs to deploy with my application. My app.jar and my lib.jar are in the same directory. My Manifest looks like:
    Manifest-Version: 1.0
    Main-Class: parser.Parser
    Class-Path: lib.jar
    Class-Path: ...Still get the error: NoClassDefFoundError.
    Main Class is found but not my lib. Can somebody help?
    regards ak

    Hi CeciNEstPasUnProgrammeur,
    many thanks. I was blind reading the Java tutorial...
    Best regards,
    ak

  • Problems with exporting a .jar file

    Hi there,
    I'm working on a small java game and wanted to export in as a jar file.
    The program runs fine in the IDE and it generates the jar without any warnings.
    However, when i try to execute the jar, it simple "blinks" the basic frame and exit.
    A better description might be, that it looks like the Jframe opens, but then closes again quickly.
    I'm using Eclipse as IDE, and follow the Export wizzard.
    My project is devided like this:
    package : framework.
    package: sound.
    package: sprite.
    folder: sounds.
    folder: sprites.
    I'm guessing it somehow can't find the images, but as i said, it runs fine in the IDE.
    My MANIFEST looks like this:
    Manifest-Version: 1.0
    Sealed: true
    Main-Class: framework.EagleFlight
    Hope you can help.

    Hi,
    Thanks for your answer.
    I can export it from Netbeans, but not Eclipse.
    However, from Netbeans I get no sound, when executing the jar.
    Anyway, I'm happy enough with the exporting, now I just need to get sound, for which i have
    made another thread here.

  • Problems with syncing and transferring files

    Hi there. Im having problems with syncing my Ipod Touch and uploading files. Ive managed to transfer multiplr MP3 fils but i noticed that when i disconnectktwith my PC. All the sings are gone. What could have haplened?
    Please help.
    Thanks.

    Apologies for the misspellings.
    Basically i have tried uploading my MP3 files (one by one) in my device. then i tried uploading films. then when i disconnected my device all my songs on the device is gone. i do not know what happened exactly.
    it would seem the current iTunes version is "unstable". having uploaded 50 songs, doing them one by one only to find out out it got wiped out in the device for some reason.
    any explanation for this?
    Thank you.

  • [solved] Problem with Amarok and flac-files

    When I installed Arch for the first time a couple of months ago, I was happy to find that some flac-files that didn't play in Amarok on my Debian installation was now played back perfectly. However, upon trying to play these files today, Amarok refuses to play them. I get an error stating that there is no suitable demux plugin for the files. Other flacs play back fine though, and the problem files play back perfectly in mplayer.
    Another thing I would be very happy to resolve is that I have a few files that use japanese in their tags. IIRC these displayed correctly in Amarok on my Debian install, but in Arch all I see is squares where there should be japanese, despite me installing both arphic-ukai and arphic-uming packages. What am I missing?
    All help appreciated!
    Last edited by Emphrygian (2007-04-20 22:36:45)

    Your tip worked like a charm and the files now play perfectly in Amarok once again.
    I solved my second problem by installing the ttf-sazanami package from AUR and adding both sazanami gothic and sazanami mincho as substitute fonts for Sans Serif (my default font) in qtconfig (not sure that I really needed both though, but hey, it works now ).
    Last edited by Emphrygian (2007-04-20 22:35:37)

  • Problem with images in .jar file

    Hi all!
    I've got a severe problem when deploying an application via web start:
    the images withhin a deployed .jar file are not found.
    So far I've tried a number of things to get the images back, none of which are working.
    I've found different threads concerning this topic, e.g.:
    http://forum.java.sun.com/thread.jspa?threadID=396363
    http://forum.java.sun.com/thread.jspa?threadID=465795&messageID=2141351
    but sadly, they didn't help me out.
    Here is my code I'm using:
      private ImageIcon loadIconFromClassLoader(String tszRelPath)
        ImageIcon tIcon = null;
        cCat.info("tszRelPath = "+ tszRelPath);
        // this line simply leads to a crash of the whole application
        //tszRelPath = tszRelPath.replaceAll("\\", "/");
        if(!tszRelPath.startsWith("/"))
          tszRelPath = "/" + tszRelPath;
        cCat.info("modified tszRelPath = " + tszRelPath);
        URL tURL = ClassLoader.getSystemResource(tszRelPath);
        if(tURL == null)
          // this too crashes my application
          //tURL = PlainResourceProvider.class.getResource(tszRelPath);
        if(tURL != null)
          tIcon = new ImageIcon(tURL);
        return tIcon;
      }I've also tried
    PlainResourceProvider.class.getClassLoader().getResource()PlainResourceProvider is part of the .jar that involves the images.
    Of course all the .class files in the .jar file are easily accesible
    I would be so thankful, if just anyone could help me to solve this problem.
    I am going crazy.
    Thanks in advance, Christoph

    You should take care of the directory structure according to the package structure.
    I for example have this jar:
    C:\source\java\ebank2_util\smsunlock>unzip -l pro-ebank_sms_unlock.jar
    Archive:  pro-ebank_sms_unlock.jar
    Length    Date    Time    Name
          0  10-28-05  17:27   hu/
          0  10-28-05  17:27   hu/khb/
          0  10-28-05  18:17   hu/khb/smsunlock/
        256  11-07-05  16:33   hu/khb/smsunlock/DButils$MySQLException.class
       4229  11-07-05  16:33   hu/khb/smsunlock/DButils.class
       1700  11-07-05  16:33   hu/khb/smsunlock/GUI$1.class
       2318  11-07-05  16:33   hu/khb/smsunlock/GUI$2.class
        988  11-07-05  16:33   hu/khb/smsunlock/GUI$3.class
       1402  11-07-05  16:33   hu/khb/smsunlock/GUI$mywl.class
       5630  11-07-05  16:33   hu/khb/smsunlock/GUI.class
        818  11-07-05  16:33   hu/khb/smsunlock/LimitedLength_TextField.class
       2452  11-07-05  16:33   hu/khb/smsunlock/Main.class
        900  11-07-05  16:33   hu/khb/smsunlock/MyInputStream.class
          0  11-07-05  16:33   META-INF/
         98  10-27-05  15:53   META-INF/manifest.mf
         90  11-07-05  16:33   hu/khb/smsunlock/properties
      20881                    16 filesAnd the resource is loaded like this from hu.khb.smsu.Main:
    InputStream is = new MyInputStream( Main.class.getResourceAsStream( "properties" ) );

  • Windows 8 Elements 11 Problem with DNG and CR2 files

    Have a Windows 8 machine with Elements 11 which has Camera Raw 7.4 installed and showing correctly in the editor. The Browser shows thumbnails of the DNG and CR2 files, but when an attempt is made to edit them, the editor opens but does not open the file. Same thing happens if I try to open the file using the File Open from the menu.
    Also I have been through the help and forums and found an article about opening jpeg files as Camera Raw files (http://blogs.adobe.com/pselements/open-jpeg-files-in-adobe-camera-raw-in-photoshop-element s/) and this does not work either.
    Help please !

    Disclaimer:  The following applies to WINDOWS EXPLORER.  I don't use Bridge so I don't know if it's applicable at all to Bridge.
    Adobe does not provide a codec for viewing Canon raw files as thumbnails.  Canon has one for free but it only works on a 32 bit Windows system.
    Early this year I found a free download for displaying raw file thumbnails that works on an x64 Windows system.  Since that time the author realized there's a real demand for this software and has started charging for it.  In any case, I find it works very well.
    http://www.fastpictureviewer.com/codecs/
    -Noel

Maybe you are looking for