Generate Jar File - Java Netbeans with Mysql localhost

I have created a java application in netbeans, and I intend to create an installer for the project.

For this I have created a jar file of the application, but I'm using the mysql database localhost.

How can I generate Jar File with Mysql localhost .

Can anyone help me please?

Thanks and regards

-----------------------------Edit---------------------------------------

Maybe not the best way to express myself, what I mean is that the database is created locally (localhost).

The connection of the application with the database is done this way:

Class.forName("com.mysql.jdbc.Driver");

return driverManager.getConnection("jdbc:mysql://localhost/database","root", "root");

I want to create a jar file of my application that has a database created locally.

Answers


I am going to explain a few things:

  1. You do not need to hard - code the Connect URL into your code. This is why you are asking for ways of creating the database as localhost. I suggest you do not hard code the Connect URL in the code. Instead write it in an editable File either a Properties file or even a text file. Let the Application read the Editable file and pass the Parameters to the Code.

  2. An Application running in your Local Machine where the database is will connect using Localhost. But a the same Application running remotely from another Machine whether in the Internet or Local access network will not Connect this way.That is why I am insisting on NOT Hard-Coding the Connect String.

  3. The database Name, user, and Password Including the Host will change from time to Time depending on which environment the Application is running in. So again if the environment changes and the variables are not the same the Application will Not Connect to the database.

Suggestion:

User a Properties file:

db.host=192.168.1.23
db.user=root
db.password=root
db.dbname=database

Load the file as a Properties file:

Properties prop = new Properties();
    InputStream input = null;

    try {

        input = new FileInputStream("config.properties");

        // load a properties file
        prop.load(input);

        // get the property value and print it out
        System.out.println(prop.getProperty("db.host"));
        System.out.println(prop.getProperty("db.user"));
        System.out.println(prop.getProperty("db.password"));
            System.out.println(prop.getProperty("db.dbname"));
         //PASS YOUR CONNECT STRING 
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn =  DriverManager.getConnection("jdbc:mysql://" + prop.getProperty("db.host") + "/" + prop.getProperty("db.dbname"), prop.getProperty("db.user"), prop.getProperty("db.password"));

    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

This way you will never have to worry about what database the application is running on as you will just have to edit the config.properties and the Application will do the rest.

I hope I gave you an answer or better still other ideas on how to handle your situation.


Need Your Help

How do you to implement Android 4.0 Restful, HTTP post request

android http http-post android-4.0-ice-cream-sandwich

Since they changed the way we make HTTP request in the latest Android SDK, I have not been able to find a tutorial that shows how to make HTTP post request. Especially for login. So I would like to...