Java表不是从mysql创建的

时间:2014-08-06 22:48:57

标签: java mysql sql

此mysql脚本无法正常运行。我尝试执行查询以在phpmyadmin中创建表并且它有效。创建了数据库但是没有创建表,我没有得到任何错误/堆栈跟踪。 这是我的代码

public void createDatabase() {
    java.sql.Connection conn = null;
    java.sql.Statement stmt = null;
       try{
          // Register JDBC driver
          Class.forName("com.mysql.jdbc.Driver");

          // Open a connection
          System.out.println("Connecting to a selected database...");
          conn = DriverManager.getConnection(DB_URL, USER, PASS);
          System.out.println("Connected database successfully...");

          // Create database
          System.out.println("Creating table in given database...");
          stmt = conn.createStatement();
          String createdatabase = "CREATE DATABASE TimePoints;";
          stmt.executeUpdate(createdatabase);
          System.out.println("Created the database.");

          // Create table
          System.out.println("Creating table in given database...");
          stmt = conn.createStatement();
          String createtable = "CREATE TABLE players (playername VARCHAR(38), playertime BIGINT);";
          stmt.executeUpdate(createtable);
          System.out.println("Created the table.");

       }catch(SQLException se){
          // Handle errors for JDBC
          se.printStackTrace();
       }catch(Exception e){
          // Handle errors for Class.forName
          e.printStackTrace();
       }finally{
          // Finally block used to close resources
          try{
             if(stmt!=null)
                conn.close();
          }catch(SQLException se){
          }// do nothing
          try{
             if(conn!=null)
                conn.close();
          }catch(SQLException se){
             se.printStackTrace();
          } //end finally try
       } //end try
       System.out.println("Goodbye!");
}

0 个答案:

没有答案