creating a database in mysql from java

前端 未结 7 1943
情深已故
情深已故 2020-12-30 12:06

Could you help with this problem.

I\'m trying to create and then use a database called TIGER.

I have no problem if I create the database in MySQL and it runs

7条回答
  •  执笔经年
    2020-12-30 12:44

    Try with this code.

    public class DbStuff {
    
        private static String jdbcDriver = "com.mysql.jdbc.Driver";
        private static String dbName = "TIGER";
    
    
        public static void main(String[] args) throws Exception {
            Class.forName(jdbcDriver);
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/?user=root&password=");
            Statement s = conn.createStatement();
            int Result = s.executeUpdate("CREATE DATABASE "+dbName);
        }
    }
    

提交回复
热议问题