Access MsAccess DB within Jar

Is it advisory to include a MsAccess Database into an executable Jar?
Will the program able to access the database and store/load data from it?

You are not using a very good CSV reader if it won't
allow input from a stream. Have you looked at opencsv
from http://opencsv.sourceforge.net/ . This will
allow the construction of a CSV reader from a Reader
which of course can be constructed from an
InputStream.
Also, the CSV Parser from
http://ostermiller.org/utils/doc/ also allows input
from an InputStream so you can take your choice..I'll remember that going forward, however, way too much code would have to be changed now not just for CsvReader but XMLWriter, XMLReader, TextReader, HTMLReader, etc.
I am now trying to write a "function" that will render the files for me, but I'm running into a syntax snag here and I don't know how to solve it:
        InputStream in =
                myClass.getResourceAsStream(packagePath.replace(".", File.separator) +
                File.separator +
                fileName);
        try {
            OutputStream out = new FileOutputStream(filePath);
            int data;
            while ((data = in.read()) != null) {
                out.write(data);
            out.close();
            in.close();
            return FileFunctionality.isFile(filePath);
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }I am getting "Incompatible types: int and <nulltype>" at
          while ((data = in.read()) != null) {
                out.write(data);
            }And if I change "null" to false, I get "Incompatible types: int and boolean", and it just keeps going.
What on earth do I write?
Phil

Similar Messages

  • Accessing Video File within .Jar

    Ok, I am creating a project where I am using JMF to display several pre-created videos. The finished project is going to be placed on a cd and submitted in a contest. Because of this, I am compiling the finished project into an executable .jar file. From my previous experiences, I have found that accessing files inside a jar is much more complex than accessing just any old file. The only way I have found to successfully access files inside a jar is through InputStreams (opposed to URLs). This is where my issues begin.
    I have been searching throughout the internet for the past 2 days trying to find any way to create a Player using a type of InputStream. This doesnt seem to be possible the way it is set up. My obsticle here seems to be getting the Manager to realize the File. Here is what I've tried and the errors I got:
    File -- NoPlayerException -- Expected. When creating a file, it doesnt know to look inside the jar for the file, but to the location of the jar instead. Perhaps there is a way to tell URL to look for the file inside the jar. If so, please tell me how.
    File movie = new File("video1.mpeg");
    JOptionPane.showMessageDialog(null, "File: " + movie + "\n URL: " + movie.toURL() + "\n URI: " + movie.toURI() + "\n URL Parsed URI: " + movie.toURI().toURL(), "Error", JOptionPane.ERROR_MESSAGE); //JOptionPane used to display background information while program is running after compiled in .jar
    MediaPanel mediaPanel = new MediaPanel(movie.getURL());
    InputStream -- Compiling Error -- So my primary method of getting Files inside jars are out the window since there is no way to get the URL of InputStreams.
    InputStream movie = getClass().getResourceAsStream("video1.mpeg");
    MediaPanel mediaPanel = new MediaPanel(movie);
    Creating MediaLocator to file location -- java.net.MalformedURLException: no protocol: video1.mpeg -- I assume that basically means I'm screwed.
    MediaLocator movie = new MediaLocator("video1.mpeg");
    JOptionPane.showMessageDialog(null, "File: " + movie + "\n URL: " + movie.getURL(), "Error", JOptionPane.ERROR_MESSAGE);
    MediaPanel mediaPanel = new MediaPanel(movie.getURL());
    Using URL to get into .jar -- NoPlayerException -- No clue about this one. Just tried this a minute ago.
    URL movie = HannibalProject.class.getResource("video1.mpeg");
    JOptionPane.showMessageDialog(null, "URL: " + movie, "Error", JOptionPane.ERROR_MESSAGE); // Displays "URL: jar:file:/G:/Latin/HannibalProject.jar!/video1.mpeg" I do not know if this is correct or not, perhaps someone could tell me.
    MediaPanel mediaPanel = new MediaPanel(movie);If anyone can help me with this, I will be GREATLY appreciative. If anyone needs more information, additional code snippets, ect. please ask and I'll provide what is needed to help me.
    Edited by: Aussiemcgr on Jan 10, 2010 7:03 PM

    And there arises the pain-in-the-ass that is not yet clear to me. For this particular thing, it needs to be an application, not an applet. Which means I have to make it an executable (alternative might be a .bat, havent played with those for anything other than scripts) instead of something embedded. For whatever reasons, this is the efficiency of the school system or whatever the hell it is.
    The simple fact in all of this is that I have no information about the computer this is going to be ran on. Effectively, I am doing this all in the dark right now because I have been given NO guarantee that the computer(s) I attempt to run this on will even have the Java Virtual Environment on it. And, unfortunately, I have no way of finding any of this out because the Computer Program category of these things are not yet been taken seriously so preparation for judging is a last-minute thing.
    Basically, I am wanting to do this with the least amount of possibilities for Murphy's Law (which means I probably shouldnt be using JMF to begin with, but I hate that incomplete feeling) to happen. For the dark abyss I am traveling into, I'm wanting to leave as little external dependencies as possible. For applets, I have to assume that the computer has some sort of browser (sounds stupid, but it is the school system). Not to mention I've designed it from the ground up to work as an application, instead of an applet (roughly 20 hours of work so far, including text research and coding).
    The contest is Jan 30 so the date is approaching real quick. Quite honestly, the more I am looking at it, the more I am starting to consider getting rid of the videos altogether since I am pretty much done with the project with the exception of that. I would have 9 videos total (made only 1 to make sure it would work before making the other 8). The videos itself would only add an additional flair at best, and pretty much guarantee the 1st place for me. My teacher thinks my program's current capabilities, with just a mouse hover and mouse clicking interface with some animated gifs that allows access to several neatly displayed texts, would probably win me first place. However I feel I would go crazy if I actually had legitimate competition for once and lost because I didnt include this damn multimedia. Not to mention I want to include this on my portfolio in the somewhat distant future (along with my Poker Program I finished last month)...I dont know where I'm going with this...

  • How can i access the stepname within a steps post-expression?

    How can i access the stepname within a steps post-expression?
    i only saw the step-id of the step: Step.TS.Id
    is there a pssibility to get the stepname from the id?
    thank you!

    Hi Fischer,
    use the expression NameOf(Step).
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Need info on Accessing portal services within a Web Dynpro application

    Hi,
    I need information on Accessing portal services within a Web Dynpro application.I want to explore this topic.Can anyone give useful links?
    Thanks in advance.
    Rajani N

    Hi
    how to reference  a portal service with web dyn pro ?
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/ep/how%20to/how%20to%20access%20a%20portal%20service%20within%20a%20web%20dynpro%20java%20application.pdf
    http://help.sap.com/javadocs/NW04S/current/wd/com/sap/tc/webdynpro/clientserver/portal/WDPortalUtils.html
    Best Regards
    Jakub Krecicki

  • I am unable to access Bridge CS6 within Photoshop CS6

    I am unable to access Bridge CS6 within Photoshop CS6 using the File menu>Browse in Bridge. Instead, I receive an error message stating that "Bridge CS6 was not found on this system.  To use this command, please reinstall Bridge CS6".  Also, Mini Bridge fails to connect with Bridge CS6. Any suggestions?  I'm using Mac Operating System 10.6.8

    Hi Pragya,
    I uninstalled and reinstalled Photoshop CS6 and the problem has not been solved.  The only way I am able to open Bridge is through its own application folder. Once I'm in Bridge, I can access Photoshop CS6 by going to the file menu and choosing  Open With > Photoshop CS6. Bridge seems to be able to comminicate with Photoshop CS6 but Photoshop CS6 is unable to recognize or find Bridge CS6.  Any other suggests? Thank you.
    Regards
    Tzoel

  • Static method to read text file within JAR.

    I've a small problem. I've got my JAR file stuff working great, so I thought I'd give a go to running it via WebStart. Through a little research, I've found that if you're distributing your application via WebStart, you need to pack up everything in a JAR file. This is no problem for the JDBC drivers, because its already in a JAR, so I should be able to distribute that fine.
    I've managed to digitally sign my application JAR and have a preliminary (i.e. untested) JNLP file set up.
    My problem is, my application gets its available data sources from an external text file. I've already written my own file I/O class which I use in my "commonfiles" package to read in a text file and return it as an array with each element holding a line from the text file. This class is basically just a bunch of static methods.
    So instead of rewriting this, I thought I'd just add a boolean flag to this method to state whether to load this file from the external file system or the JAR file. I've found out that to load a text file from within the JAR you have to use something like: -
    String str = (this.getClass().getResource("/myData.txt")).getFile();
    java.io.File fil = new java.io.File(str);
    java.io.FileReader fr = new java.io.FileReader (fil);
    java.io.BufferedReader bin = new java.io.BufferedReader (fr) ;The sticking point is that my method (ReturnFileAsArray()) is declared as static, because my own FileIO class is just a bunch of static methods to do file I/O stuff. Therefore, I can't use the above method because of the instance variable "this" (I assume).
    Is there any way I can load an included text file as above without having to declare my method as an instance method? I guess I could write a seperate class to do this for my commonfiles package, but I'd rather not if possible.
    Any ideas?

    Don't put a "flag" and code different ways to read files depending on whether it's in a JAR or not. Just use
    the getResource/getResourceAsStream API regardless. Hmmm.....so that will load it from either place depending on the situation? I keep getting a NullPointerException doing that, on this line: -
    String strFileName = (FileIO.class.getResource(fileName)).getFile();...although I've only tried it using the external local filesystem file (in the same directory) as I've not really finished setting up my WebStart stuff yet.
    Here is the method in question...
    public static String[] ReadFileAsArray(String dirName, String fileName, boolean bFromJAR) {
            String[] resultStringArray = null;
            StringBuffer strBuffer = null;
            StringTokenizer strTokenizer = null;
            FileReader fReader = null;
            BufferedReader bReader = null;
            int iElementCount = 0;
            if ((dirName.length() < 1) || (fileName.length() < 1)) {
                // Null parameters found. Failure.
                return null;
            } else {
                // Parameters correct, continue.
                try {
                    // Read the file contents and convert to String array.
                    //if (bFromJAR) {
                        // Open file from within JAR file.
                        String strFileName = (FileIO.class.getResource(fileName)).getFile();
                        File jarFile = new File(strFileName);
                        fReader = new FileReader(jarFile);
                    //} else {
                        // Open from local filesystem.
                    //    fReader = new FileReader(dirName + File.separator + fileName);
                    bReader = new BufferedReader(fReader);
                    strBuffer = new StringBuffer();
                    while (bReader.ready()) {
                        strBuffer.append(bReader.readLine() + "%%");
                    strTokenizer = new StringTokenizer(strBuffer.toString(), "%%");
                    resultStringArray = new String[strTokenizer.countTokens()];
                    while ((strTokenizer.hasMoreTokens()) && (iElementCount < resultStringArray.length)) {
                        resultStringArray[iElementCount++] = strTokenizer.nextToken();
                    bReader.close();
                    return resultStringArray;
                } catch (IOException e) {
                    return null;
        }I'm calling it using: -
    // Load the external file into a String array, one row for each element.
    String[] fileArray = FileIO.ReadFileAsArray(System.getProperty("user.dir"), "datasources.dat", true);Cheers on any info on this.

  • Access wav-files in jar-archives (URL works, File works not)

    Hi there!
    The un-jar-ed application works fine, but I have a problem with accessing files in jar archives.
    URL url = Classname.class.getResource("testdir/test.wav");works fine (and loading images works this way), but as soon as I try to get the file
    File file = new File(url.getFile());I get an null-exception.
    (in my case, I use the jmf package to play the sound-files, and I get the problem when I try to instatiate the MediaLocator
    MediaLocator mediaLocator = new MediaLocator(url);but I think the problem is the same)
    Thanx for help

    works fine Then keep doing it that way. What's the problem? It's true that you can't access something in a jar archive via a File object, so don't do that.

  • Accessing Essbase cubes within a HP application using Essbase add-in

    Hi All,
    I've been told in the past by Oracle Support personnel that accessing the Essbase cubes within a Planning application using the MS Excel Essbase add-in is "a very bad idea" and that such an approach "is not supported\recommended by Oracle due to potential issues" (which the support person could not tell me about).
    Unfortunately, I have not found any information in the Planning documentation which supports or not this recommendation.
    As such:
    1. Could anyone point me in the right direction in terms of finding out whether it is recommended\supported (or not) for users to access Essbase cubes within a Planning application using the Essbase add-in?
    2. Has anyone ever experienced issues accessing Essbase cubes within a Planning application using the MS Excel Essbase add-in? If yes, what were these issues??
    PS: We are on v9.3.1.x of Essbase\Planning and will be moving over to v11.1.2.x in the next 6-8 months.
    Thanks in advance,
    JBM

    Hi Rob,
    Thank you for your prompt & informative response.
    On the topic of metadata, I am aware of what happens when changes are made directly to an Essbase outline which falls under a Planning application without going following the proper method ... and I agree that it ain't pretty! :-)
    On the topic of locking\sending data to the Essbase cubes within a Planning application, I also understand that it works quite well in as much as the data is saved in the appropriate intersections within the Essbase cube, as permitted by the security assigned to the user.
    I was more interested in whether such a practice of locking\sending data directly to Essbase cubes within a Planning application was actually encouraged or discouraged by Oracle.
    And please correct me if I am wrong but from what you are saying, it seems to me that it is neither as:
    - on one hand, the "Essbase Write" HSS feature allows administrators to create security groups and assign this type of provisioning to security groups in question;
    - on the other hand, Oracle Support seems to be verbally discouraging such a practice for no real reasons related to technological limitations;
    The problem that I have is that because some users at our site know that they can lock\send data to Essbase cubes within a Planning application and as a result, not only want to get us to grant similar lock\send access to other users but are now more reticent than ever to move away from the Essbase add-in as a means to load\submit data to a Planning application. And that's why I was after some formal recommendation from Oracle as to whether it is a recommended practice or not.
    Anyway, any suggestions would be much appreciated.
    Regards,
    JBM

  • How do you access attachments embedded within survey results?

    How do you access attachments embedded within survey results?

    This is a tutorial explaining attachments:
    http://forums.adobe.com/docs/DOC-2656

  • Can free online books be downloaded to memory of ipad2 so that book can be accessed when not within wi-fi range

    can free online books be downloaded to memory of ipad2 so that book can be accessed when not within wi-fi range

    It depends on what books you're referring to. All books from the iTunes Store are downloaded to your iPad and except for any special features the book may contain that requires an Internet connection will be readable without such a connection.
    If you're talking about books from some other source, we'd need to know the source before we could offer opinions.
    Regards.

  • How can I access EJB  through executable jar file?

    Hello buddies!!
    I wonder if anyone could give me an explanation of how accessing EJB through executable jar file?Thanks!!

    Hi there,
    You'll need to install the J2EE SDK on the client and include the <j2ee install dir>\lib\j2ee.jar file in your CLASSPATH along with the Client Jar file that was generated by the deploytool when you deployed the application.
    In your client code the Context properties are as follows:
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    p.put(Context.PROVIDER_URL, "iiop://hostname:portnumber");
    Context cntx = new InitialContext(p).Hope this helps
    Amanda
    Developer Technical Support
    Sun Microsystems
    http://www.sun.com/developers

  • Applet inside a JAR: Cannot access other classes within the JAR

    Hello,
    Description
    Web app + applet (packaged in a JAR)
    I have followed this tutorial
    JAR contents
    package mypackage
    SimpleApplet.class
    SimpleObj.class
    _"SimpleApplet" uses "SimpleObj"_
    package mypackage;
    public class SimpleApplet extends JApplet {
        @Override
        public void init() {
            SimpleObj obj = new SimpleObj();
    HTML code
    <applet archive="SimpleApplet.jar" codebase="." code="mypackage.SimpleApplet.class" width="800" height="600" />
    SimpleObj cannot be found (Java Console)
    java.lang.NoClassDefFoundError: mypackage/SimpleObj
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: mypackage.SimpleObj
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 8 more
    Caused by: java.io.IOException: open HTTP connection failed:*http://localhost:8080/SimpleApp/mypackage/SimpleObj.class*
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 12 more
    Exception: java.lang.NoClassDefFoundError: mypackage/SimpleObj
    It looks like JRE does not search for the SimpleObj class inside the JAR, but tries to get it from the server...
    Any ideas?
    Thanks in advance,
    Gerard
    Edited by: gsoldevila on Dec 10, 2008 2:05 AM

    misread, deleted
    Edited by: atmguy on Dec 10, 2008 1:12 PM

  • How to use database file within jar archive

    Hi. I'm quite new in Java programming, and I'm wondering if what I did makes sense or not.
    In my applet I'm using a MS Access Database file, which is contained in the same Jar Archive like the Applet class file. I tried and tried to use this Database file directly but it wouldn't work. Than I read in some other forum that it is not possible to use the database file directly within the archive. First question: Is that true?
    Than I desided to extract the DB file in the init() method of my applet to the default temporary foulder. When the program is closed I use the destroy() method to delete it again. Everything works well now. But is this the typical way this is done?
    Thanks for help!

    Hi,
    here is the code which extracts the database file out of the jar archive (the same archive in which the class file is):
    //get the user temporary folder
    File TempFolder = new File(System.getProperty("java.io.tmpdir"));
    //create (empty) db file
    efile = new File(TempFolder, "steelSections.mdb");
    // if database file is not yet extracted
    if (!efile.exists()) {
    //get an input stream for the database file
    InputStream in = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(
    "FaST/db/steelSections.mdb"));
    //create an output stream for the db file on the file system
    OutputStream out = new BufferedOutputStream(new FileOutputStream(efile));
    //-Buffer to copy the data
    byte[] buffer = new byte[2048]; //buffer to copy the binary
    for (;;) {
    int nBytes = in.read(buffer); //read data
    if (nBytes <= 0)
    break; //no more data to read
    out.write(buffer, 0, nBytes); //write data
    out.flush(); //close out and in streams
    out.close();
    in.close();
    If you have the db file in an other jar archive file you need a referenze to the entry in the other jar archive. I'm not sure how to get this, but I'm sure you fill find a solution by searching in this forum...
    Good luck!

  • Creating a JAR in Eclipse...can't access files in the JAR properly.

    Hi all! I'm a newbie at JAR creation, and am having troubles. I have a project that loads images from image files in my project. I can create the JAR and all, and it runs, but the buttons that have ImageIcons with those IO loaded images are blank. I've tried to include the images when creating the JAR, but it keeps acting like the images never existed. When I run the JAR and have the images separately included in the directory (instead of packing them up too), it won't work as well...UNLESS those images are put in my $HOME directory (Linux).
    Does anyone know how I can properly refer to the images that I'm trying to pack into the JAR from within the JAR? Or, is there a way for the JAR to understand where those images are supposed to be (redirect the focus from the $HOME directory to the JAR's directory)? Any help would be greatly appreciated! :)
    -Keith

    Hi,
    Can the user execute the program through explorer? In Windows Server 2003, the Users group does not have Read and Execute permissions to the command processor (Cmd.exe). 
    You could refer to the article below to resolve the issue:
    "Access is denied" error message when you run a batch job on a Windows Server 2003-based computer
    http://support.microsoft.com/kb/867466
    Best Regards,
    Mandy 
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Accessing a File within a zip, which was archived using Applet Tag

    Hi,
    Could Any one please tell me, How to Access a File from within an Applet. The File resides inside a zip which was Archived using <Applet> Tag.
    Actually, I want to write an application which runs both online and offline. So I have chosen Applet and All the files Which I need are zipped and is Archived through <Applet ARCHIVE="example.zip">.
    Now I want to access those XML files which are inside example.zip from my Applet.
    How can I do that?
    I think I will get security Exception.
    How to get rid of this security Exception.
    Kindly Answer soon.......
    It's very urgent.
    Thanking you,
    KumudaRaj

    Did you already try signing a jarfile? If no ->>
    You can call a class inside a jar-file within the applet.
    if this class should be able to acces files the jarfile
    first has to be signed. to do this, you must generate a key.
    the complete work:
    1. write your applet
    2. write a html-page with following code:
    <APPLET code="guestbook.class" archive="guestbook.jar" width=600 height=400></APPLET>
    3. make a zip-file with the guestbook.class, guestbook.form, guestbook$1.class, guestbook$... and rename it to guestbook.jar
    4. in the console type:
    keytool -genkey -alias YOURNAME
    5. sign the key to your jarfile with:
    jarsigner guestbook.jar YOURNAME
    6. try the applet. a warning should appear which you have to answer
    with YES then it should work
    my trouble is that i cant acces files anyway because right now i don�t
    alreadv have the clue to get the right (absolute?) path for the file. means i get an ioexception because the applet cant find the file :-((
    does anyone know how to solve this problem then? my code is:
    FileReader Stream = new FileReader("/members/Ui97u8g4f6b89mj90kh5gbr4ecf6KXC4/guestbook.txt");
    ...

Maybe you are looking for

  • External Harddrive no longer showing up

    so my old hard drive (external) has been playing up for a while, i daisy chained it to another and to my imac and tried to transfer everything so i can wipe it and reformat it. i transferred most things but now it just won't show up on my mac... I'm

  • Sales org 2 view in material master

    hi gurus, Iam not able to see all fields in sales org 2 view in material master and i would like to know how to configure to restrict end users not to change it . thank you in advance. regards, Gopio

  • MBP  Sluggish and Indecisive

    My Macbook Pro is from mid 2010, with a 2.66 ghz processor, 4gb memory, and  OS X 10.9.5 maverick software. I have 115.6 GB free out of 319.21 gb of storage. My computer has functioned perfectly since I got it but during the last 2 months has become

  • Aeroplane mode wont go away

    The phone keeps bringing up a request to go to aeroplane mode. How do I get rid of this?

  • How should I deal with it in the BMM Layer

    Hi all, I need a suggestion in a problem. Here is the scenario, In the physical layer, There are some fact to fact joins. ProductFact ----< PolicyFact ----< PolicyCoverFact ----< ClaimFact ----< ClaimPaymentFact ----< CorrespondenceFact There are som