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);
  }
}









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 can create a jar file - Java Beginners
how can create a jar file  plz any one help me which file can i create the jar file plz give exact command  Hi The basic format... that you want to create a JAR file. * The f option indicates that you want
How to Create Jar File using Java
How to Create Jar File using Java Programming Language A Jar file combines... in the jar file.  In this section, we are going to create our own jar file... is to be combined and the path of jar file where we want to create the jar file. Here
how to create a jar file for my packages classs - Struts
how to create a jar file for my packages classs  how to create a jar file for my packages classs in struts application .we don't want to see the see the classes other persons
how to create a jar file for java classes? - Java Interview Questions
how to create a jar file for java classes?  I have 2 classes x1 and x2. packages names are com.bank.xyz; how to create a jar file for classes.  Hi Friend, Please visit the following link: http
Create JAR file - Java Beginners
Create JAR file  Respected Sir, I got the answer from your side. But do let me know, isn't there any other way of making a JAR File. Simply like... to make a JAR file and run it easily on any computer. For that purpose i want
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...-plugin which is used to create fat jar file. The fat jar file is the jar file... to create jar file which includes all the dependencies and project resources
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 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 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
How to use JAR file in Java
and their operation: Create a JAR file - jar cf jar-file input-file(s... jar-file archived-file(s) 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
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
jar file
jar file  how to create a jar file in java
jar file
jar file  steps to create jar file with example
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 convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
jar file
jar file  jar file where it s used
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 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 XML file - XML
How to create XML file  Creating a XML file, need an example. Thanks!!  To create XML file you need plain text editor like note pad. After... language has many API's to create xml file from program.Here is the code example
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
database connection
database connection  how to connect the jsp page with database
Connection to Database
I manually make a connection to MySQL database in my web pages? How joomla... is the code how I am connecting to MySQL: I am connection to MySQL database in 2... question is that how I can properly connect to my SQL database where I need
database connection
database connection  i wanted to no how to connect sqlite database through netbeans? is it posible to connect it to a database that is on a remote pc? thank you
How To Create a New File
How To Create a New File In this section we will discuss about how to create... a simple example which will demonstrate you about how to create a new file... store String, characters, numbers etc. In Java to create a File for storing
Create a database
; Then create connection with database. The connection  is included... Create a database       In this section, we will teach you to create a database.  First of all
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
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
Create XML file from flat file and data insert into database
Create XML file from flat file and data insert into database... have developed an application to create xml file from flat file and data...". 2). Create a file "FlatFileXml.java"  used to create
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
File path for jar file
File path for jar file  Hi Experts, I have created one eclipse... jar file of that application, unfortunately it is giving the error that resource not found for the template file. Also I had tried to get that path from user
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
how to create database and table using jsp
how to create database and table using jsp  hi frnds...., i want to create database and table in mysql using jsp.... i have an registration form(name... for each user to store their details.. so pls help me how to create individual
please help me solve this problem when i am create database connection using servlecontext
please help me solve this problem when i am create database connection using servlecontext  hi... I have create a database connection using...("db", db); } //database connection class
how to connection jsp to oracle database connections in netbeans ide
how to connection jsp to oracle database connections in netbeans ide  how to connect jsp to oracle database connections in netbeans ide?pls provide screenshots if possible
how to connection jsp to oracle database connections in netbeans ide
how to connection jsp to oracle database connections in netbeans ide  how to connect jsp to oracle database connections in netbeans ide?pls provide screenshots if possible
I want simple steps to create Jar File of Java Project - Java Beginners
I want simple steps to create Jar File of Java Project  Hello Sir How I can Create Jar File of Java Project,plz Help Me  Hi Friend...: Examples>manifest.txt 6. Create a jar file: C:\examples> jar
how to auto generate number in jsp with the database connection mysql for employee number?
how to auto generate number in jsp with the database connection mysql for employee number?  how to auto generate number in jsp with the database connection mysql for employee number?   <%@page import="java.sql.
how to auto generate number in jsp with the database connection mysql for employee number?
how to auto generate number in jsp with the database connection mysql for employee number?  how to auto generate number in jsp with the database connection mysql for employee number?   <%@page import="java.sql.
how to create online exam in jsp and database
how to create online exam in jsp and database  learing stage ,want to know how to create online exam
How to create pdf file in struts2.
How to create pdf file in struts2. In this example, you will see the how to create PDF in struts, and how to write message in generated PDF file in struts2.  For this, we requires a jar file iText.jar. It is used in java
DataBase connection with sql - Struts
DataBase connection with sql  How to connect sql and send db error in struts? what are the tag should i code in struts-confic.xml
How to Create and display Reports in Java with Database connectivity - Java Beginners
How to Create and display Reports in Java with Database connectivity  Hello Sir , I have Created Student Admission Form with Swing and MS Access 2007 Database Connection,when i will click on Print button it shows the report