Home Answers Viewqa Java-Beginners How to create a jar file with database connection

 
 


Vishal Dhole
How to create a jar file with database connection
1 Answer(s)      10 months ago
Posted in : Java Beginners

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 Pages:
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
jar file
jar file  how to create a jar file in java
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
java jar file - Java Beginners
java jar file  How to create jar Executable File.Give me simple steps to create jar files  Hi Friend, Try the following code: import...(); System.out.println("Jar File is created successfully."); } catch (Exception ex
Creating JAR File - Java Beginners
me, in letting me know, as to how to create JAR file from my JAVA source...(); } out.close(); fout.close(); System.out.println("Jar File... main(String[]args){ CreateJar jar=new CreateJar(); File folder = new File
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
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
jar file
jar file  steps to create jar file with example
Java Jar File - Java Beginners
Java Jar File  What is a Java JAR file ..and how can i open a .jar file in Java?  Just create a Jar file and Double click on it, it will automatically runs main method in that Jar : to create Project as JAR
connection
connection   how to make multiple database connection using jdbc
Regading Database connection
Regading Database connection  if we create the query table means how we retrive the query content from database
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
Runnable JAR
Runnable JAR  How to create runnable JAR file in eclipse ? Please provide me step by step demo... I am windows 7 user. I have made one jar file but when I double click it,it doesn't run. Why so
Runnable JAR
Runnable JAR  How to create runnable JAR file in eclipse ? Please provide me step by step demo... I am windows 7 user. I have made one jar file but when I double click it,it doesn't run. Why so
jar File creation - Swing AWT
in java but we can create executable file in java through .jar file.. how can i convert my java file to jar file? Help me...jar File creation  I am creating my swing applications. How can i
java database connection - Struts
java database connection  how to connect a database in struts program?  First Add two jar file1> commons-dbcp-1.2.x.jar2> mysql...; value="jdbc:mysql:///database_name?autoReconnect=true"
REQ for connection b/w jdbc and oracle database
REQ for connection b/w jdbc and oracle database    REQ for connection b/w jdbc and oracle database    The Java classes to connect to Oracle are contained in the Oracle JDBC driver jar file. For recent releases
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
creating a jar file - JSP-Servlet
. where to place the html or jsp files 2. how to create a jar file and how can i create it for a single servlet.class file how can i run my servlet file...creating a jar file  Can you give me detail answer 1. i am having
Jar file creation - Swing AWT
Jar file creation  i have developed a swing application using Net... the application i gets a JAR file a lib file is also created in dist folder..this wrks fine using IDE 1.Now i want to give the application as a jar file
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
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
connection
connection   How to get connected to my database using jsp   Please visit the following links: http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp/displaydatafrom_database1.shtml http
database connection
database connection  how to connect the jsp page with database
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
change jar file icon - Java Beginners
change jar file icon  How to create or change jar file icon  Hi friend, The basic format of the command for creating a JAR file... to create a JAR file. * The f option indicates that you want the output to go
JAR Generation
JAR Generation  Hi, I have done this code. Can u pls tell me how to create a jar for this in eclipse, this is only a single java file? package... public boolean accept(File arg0
JAR Generation
JAR Generation  Hi, I have done this code. Can u pls tell me how to create a jar for this in eclipse, this is only a single java file? package... public boolean accept(File arg0
servlet (tomcat server) and jar
servlet (tomcat server) and jar  how to create a jar file and where to place the jar file in tomecat server
how to write a code for oracle database connection in asp.net for validation.
how to write a code for oracle database connection in asp.net for validation...;/script>   Create a new project in Visual Studio using eight C# Add reference to Oracle.DataAccess.dll file. Typically this file can be found in C
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
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
Hibernate- Oracle connection - Hibernate
; Open perspective--> other in that Database Development Right click on databaseconnection --> New Oracle Added ojdbc14 Jar file path UID and password as scott and tiger. clicked Test connection. I'm getting Ping
Only change jar file icon - Java Beginners
Only change jar file icon  Dear Friend I know that how to create a jar file but i don't know How to change jar file Icon. I can change .exe file... indicates that you want to create a JAR file. * The f option indicates that you
java-jar file creation - Java Beginners
java-jar file creation  how to create a jar file?i have a folder which contains a project .. i should convert that project as an executable jar file  Hi Friend, JAR stands for the Java Archive. This file format
Create a database
; CREATE DATABASE database_name; Then create connection... Create a database       In this section, we will teach you to create a database.  First of all
Extract Jar File
Extract Jar File  How to extract jar file?   Hi Please open the command Prompt and to the jar file and write the command jar -xvf JaraFileName.jar
Creating a JAR file in Java
-name" in the source code to create a jar file for the given directory. You can... Creating a JAR file in Java       This section provides you to the creating a jar file
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
jar file with html
jar file with html  I have a jar file. On double click it shows an applet page. Please tell me how to connect that applet into html or jsp page
Correctly Open and Close database connection
; } Completely Open and Close A Database Connection Database Connection... and close database connections properly. If any database connection is open... important to close the database connection after it is used. Database connection
Creating an executable jar file
Creating an executable jar file  When I try to create jar.exe through CMD, the manifest file created doesn't contain Main-Class attribute, even though it is included in text file used during creation of jar file
connection of java file to excel file and put data from excel file into oracle db
connection of java file to excel file and put data from excel file into oracle db  how to create button on excel sheet using java swing and how we give action to that button excel sheet? how we connect excel file to java file
Jar file - Java Beginners
Jar file  Hello this is my second question and i hope atleast i will get answer i bulid a jar file of my project using netbeans but now problem is when i open that jar file in command prompt i got error exception in thread
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.