How to create a jar file with database connection

Ads
 

How to create a jar file with database connection

Hello Everyone!!! Pls Help me in this... i have a program which has a database connection with ms access & i want to create a jar file of it... I have tried with manifest file but its not working pls help me.....

View Answers

July 19, 2012 at 10:32 AM

The given code creates a jar file using java.

import java.io.*;
import java.util.jar.*;

public class CreateJar {
  public static int buffer = 10240;
  protected void createJarArchive(File jarFile, File[] listFiles) {
    try {
      byte b[] = new byte[buffer];
      FileOutputStream fout = new FileOutputStream(jarFile);
      JarOutputStream out = new JarOutputStream(fout, new Manifest());
      for (int i = 0; i < listFiles.length; i++) {
        if (listFiles[i] == null || !listFiles[i].exists()|| listFiles[i].isDirectory())
      System.out.println();
        JarEntry addFiles = new JarEntry(listFiles[i].getName());
        addFiles.setTime(listFiles[i].lastModified());
        out.putNextEntry(addFiles);

        FileInputStream fin = new FileInputStream(listFiles[i]);
        while (true) {
          int len = fin.read(b, 0, b.length);
          if (len <= 0)
            break;
          out.write(b, 0, len);
        }
        fin.close();
      }
      out.close();
      fout.close();
      System.out.println("Jar File is created successfully.");
    } catch (Exception ex) {}
  }
  public static void main(String[]args){
    CreateJar jar=new CreateJar();
    File folder = new File("C://Answers//Examples");
      File[] files = folder.listFiles();
    File file=new File("C://Answers//Examples//Examples.jar");
    jar.createJarArchive(file, files);
  }
}

Ads









Related Tutorials/Questions & Answers:
How to create a jar file with database connection
How to create a jar file with database connection  Hello Everyone!!! Pls Help me in this... i have a program which has a database connection with ms access & i want to create a jar file of it... I have tried with manifest
How to create a jar file
How to create a jar file  Hello!!!! I have a project which has a multiple classes with database connection(MS-Access) & now i want to make a single executable jar of it... so pls tell me how it will b possible for me
Advertisements
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
How to create jar file with dependencies in Maven?
Creating Jar with all dependencies - How to create jar file with dependencies..."] In this tutorial you learned how to create a fat jar file which includes...-plugin which is used to create fat jar file. The fat jar file is the jar file
How to create jar file with dependencies in Maven?
Creating Jar with all dependencies - How to create jar file with dependencies..."] In this tutorial you learned how to create a fat jar file which includes...-plugin which is used to create fat jar file. The fat jar file is the jar file
jar file
jar file  how to create a jar file in java
how to convert a jar file into .exe file
how to convert a jar file into .exe file  hi, I want convert my jar file into executable file,urgently please help me
how can i export a .jar file include .mbd file?
how can i export a .jar file include .mbd file?  i have a project... a error that can't export .jar file width the .mdb file ? how can i import this .mdb file width the .jar file? and how can i run this file on the other computer
how to create ipa file
how to create ipa file  Hi, How to .ipa file? Thanks   Hi, Please check the thread Resources have been modified iPhone. Thanks
jar file
jar file  steps to create jar file with example
How to use JAR file in Java
) To create a JAR file type "jar cf jar-file input-file(s)" in command prompt. "c" parameter means that you want to create a jar file and "f" parameter means... to digitally sign the JAR file. Users who want to use the secured file can check
How to convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
how to create tar file in ubuntu
how to create tar file in ubuntu  Hi, I have a directory with many sub directories and files in it. I want to create tar file of the directory so... this. What is easy command for this which i can run in terminal. how to create
how to create tar file in ubuntu
how to create tar file in ubuntu  Hi, I have a directory with many sub directories and files in it. I want to create tar file of the directory so... this. What is easy command for this which i can run in terminal. how to create
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
How to create a .mdf file from script (.sql)
How to create a .mdf file from script (.sql)  Hi, I have a sql database in 2008 server. now i want it to convert to 2005. so i script it. just help me to create a .mdf file back from the script
While creating a jar how to add MySQL database to project
While creating a jar how to add MySQL database to project  Hi, Please tell me how to attach MySQL database to the Java project while building a jar or their is any other process
jar file
jar file  jar file where it s used
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
jar file - Java Beginners
file. what is the manifest file, and how to create it. And tell me more about... create a JAR file, it automatically receives a default manifest file. There can.../MANIFEST.MFWhen you create a JAR file, the default manifest file simply contains
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
How To Create a New File
How To Create a New File In this section we will discuss about how to create... which will demonstrate you about how to create a new file in Java... store String, characters, numbers etc. In Java to create a File for storing
JAR FILE
JAR FILE  WHAT IS JAR FILE,EXPLAIN IN DETAIL?   A JAR file... and applications. The Java Archive (JAR) file format enables to bundle multiple... link: Jar File Explanation
database connection
database connection  hi all ready created database table using mysql database,employee payroll,attendance,employee details used database i need how to import and export excel file into database using jsp? pls help me any one
How to create bar chart using database values
How to create bar chart using database values  How to create bar chart using database values i.e excellent,good,average fields using jsp?It is like opinion poll.I want to show how many votes are came for excellent,good,average
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response

Ads