如何在javaeclipse中创建新数据库

1dkrff03  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(226)

我正在学习java,我想创建一个名为 Login 它有两列:一列被命名为 Username 另一个叫 Password .

import java.sql.*;
import java.util.*;

import javax.swing.JOptionPane;

public class sqlCreateDataBase {

    public static void main(String [] args) {

        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/;create = true", "root", null);
            Statement stmt = conn.createStatement();
            String databaseName = "Login";

            String sql = "CREATE DATABASE " + databaseName;
            stmt.executeUpdate(sql);

            System.out.println("Creating the Login table...");
            stmt.execute("CREATE TABLE login("  +
                "Username CHAR(25), " +
                "Password CHAR(10)");

            stmt.close();
            conn.close();

            System.out.println("Done");
        }
        catch(Exception ex) {
            System.out.print("Error: " + ex.getMessage());
        }
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题