Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Erstellen einer Datenbank in MySQL aus Java

Ich schlage vor, dieses Code-Snippet zu verwenden

private String jdbcDriver = "com.mysql.jdbc.Driver";
private String dbAddress = "jdbc:mysql://localhost:3306/TIGER?createDatabaseIfNotExist=true";
private String userName = "root";
private String password = "";

private PreparedStatement statement;
private ResultSet result;
private Connection con;

public DbStuff() {
    try {
        Class.forName(jdbcDriver);
        con = DriverManager.getConnection(dbAddress, userName, password);
    } 

    catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
    catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}