logo
down
shadow

Eclipse Luna : Tool to Create new MySQL database


Eclipse Luna : Tool to Create new MySQL database

By : skullv2
Date : November 17 2020, 04:28 AM
fixed the issue. Will look into that further Why would you need a tool, when it's this simple to create a database and tables with a Java application?
code :
package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateDatabase implements Runnable {

    private Connection connection;

    private Statement statement;

    private String databaseAddress;
    private String logon;
    private String password;

    public CreateDatabase(String logon, String password) {
        this.logon = logon;
        this.password = password;
        this.databaseAddress = "localhost:3306";
    }

    @Override
    public void run() {
        try {
            connect();
            createDatabase();
//          dropTable("user_account");
            createUserAccountTable();
            commit();
            disconnect();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    private void connect() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://"
                + databaseAddress + "/?" + "user=" + logon + "&password="
                + password);
        statement = connection.createStatement();
    }

    private void createDatabase() throws SQLException {
        String sql = "create database if not exists accounts";
        statement.execute(sql);
        displayUpdateCount(sql);
        sql = "use accounts";
        statement.execute(sql);
        displayUpdateCount(sql);
        sql = "set names 'utf8'";
        statement.execute(sql);
        displayUpdateCount(sql);
    }

    private void createUserAccountTable() throws SQLException {
        String sql = "create table if not exists user_account ( " +
                "user_account_number integer not null auto_increment, " +
                "user_account_name varchar(40) not null, " +
                "created_timestamp timestamp not null default current_timestamp, " +
                "last_used_timestamp timestamp not null, " +
                "primary key (user_account_number)) " +
                "engine=InnoDB, " +
                "character set=utf8, " +
                "auto_increment=10000000 ";

        statement.execute(sql);
        displayUpdateCount(sql);
    }

    void dropTable(String tableName) throws SQLException {
        String sql = "drop table if exists " + tableName;
        statement.execute(sql);
        displayUpdateCount(sql);
    }

    private void commit() throws SQLException {
        String sql = "commit";
        statement.execute(sql);
        displayUpdateCount(sql);
    }

    private void displayUpdateCount(String sql) throws SQLException {
        int count = statement.getUpdateCount();
        StringBuilder builder = new StringBuilder();
        builder.append("Executing SQL \"");

        if (sql.length() > 40) builder.append(sql.substring(0, 40));
        else builder.append(sql);

        builder.append("\" resulted in ");
        builder.append(count);
        builder.append(" row");
        if (count != 1) builder.append("s");
        builder.append(" changed");

        System.out.println(builder.toString());
    }

    private void disconnect() throws SQLException {
        statement.close();
        connection.close();
    }

    public static void main(String[] args) {
        if (args.length != 2) {
            String s = "The logon and password for the database " +
                    "must be provided.";
            System.err.println(s);
        } else {
            new CreateDatabase(args[0], args[1]).run();
        }
    }

}


Share : facebook icon twitter icon
Eclipse luna Unable to read repository at http://download.eclipse.org/releases/luna/content.xml

Eclipse luna Unable to read repository at http://download.eclipse.org/releases/luna/content.xml


By : Pascal31459
Date : March 29 2020, 07:55 AM
around this issue The problem for me was that on apache-maven-3.2.5\conf\settings.xml i have a proxy, so i delete it and every thing works fine
SpringBoot via Spring Tool Suite in Eclipse Luna builds not working project

SpringBoot via Spring Tool Suite in Eclipse Luna builds not working project


By : user3531192
Date : March 29 2020, 07:55 AM
I wish this help you You already have something occupying port 8080, which from the sound of it may be caused by you having the service running when you deleted everything in your workspace.
Look at your system processes (ctrl+shift+esc if on Windows), see if you have a java process running, and kill it. It should be javaw.exe. Once the process is stopped you will be able to restart your server.
External Tool Configuration build options tab in Eclipse > Luna (i.e. Mars)

External Tool Configuration build options tab in Eclipse > Luna (i.e. Mars)


By : Dream Business Syste
Date : March 29 2020, 07:55 AM
Hope this helps You set up such custom builders via the project's Properties dialog. Open the properties, then select the Builders section. There you can use the New... button to configure a Program to run as a builder.
Can we use different JDK's for Spring tool Suite based on eclipse and eclipse luna

Can we use different JDK's for Spring tool Suite based on eclipse and eclipse luna


By : Alejandro Monroy
Date : March 29 2020, 07:55 AM
hop of those help? The first thing to understand is that Eclipse itself requires a JRE to run (preferably a JDK), and that JRE can be different than the one that your projects in Eclipse are configured to use - they are intentionally separate.
To specify the JRE that Eclipse itself runs in, you should specify it in eclipse.ini. Read that page carefully, the format is very particular. Once you've done that, your system classpath or JAVA_HOME or PATH will not matter, Eclipse prefers its own ini settings.
Is there a tool to create MySQL database model from an existing MySQL database?

Is there a tool to create MySQL database model from an existing MySQL database?


By : Kris Senden
Date : March 29 2020, 07:55 AM
I hope this helps you . If you use mysqldump with the --no-data option, you can extract the schema from the old database. There can be issues with views using this method, see this article for a workaround.
You can copy a schema in this way with something like this:
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org