我写的程序执行到这里时出错了,控制台显示Can't find file: '.\hello\@0024table.frm' (errno: 2 - No such file or directory),上网查说是权限问题,请问怎么解决?newName:hll
oldName:helloconn=DBUtil.getConnection(newName);
for (int i = 0; i < tableList.size(); i++) {
sql = "rename table "+oldName+".$table to "+newName+".$table";
ptmt = conn.prepareStatement(sql);
; ptmt.execute();
}
if(ptmt!=null){ptmt.close();}
if(conn!=null){conn.close();}

解决方案 »

  1.   

    用root用户连接数据库
      

  2.   


    public static void renameDataBase(String newName, String oldName) {
    PreparedStatement ptmt;
    try {

    //一开始必须填一个已经存在的数据库 
    Connection conn = DBUtil.getConnection("lannong");
    //创建数据库
    String sql = "create database if not exists "+newName;
    ptmt = conn.prepareStatement(sql);
    ptmt.executeUpdate(); 
    ptmt.close();
    conn.close();

    ArrayList<String> tableList = new ArrayList<>();
    //打开原来的数据库
    conn=DBUtil.getConnection(oldName);
    sql = "select table_name from information_schema.TABLES where TABLE_SCHEMA=?";
    ptmt=conn.prepareStatement(sql);
    ptmt.setString(1, oldName);
    ResultSet rs = ptmt.executeQuery();
    while(rs.next()){
    tableList.add(rs.getString("table_name"));
    }
    if (rs!=null) {rs.close();}
    if(ptmt!=null){ptmt.close();}
    if(conn!=null){conn.close();}

    for (int i = 0; i < tableList.size(); i++) {
    System.out.println(tableList.get(i));
    }
    conn=DBUtil.getConnection(newName);
    for (int i = 0; i < tableList.size(); i++) {
    sql = "rename table "+oldName+".$table to "+newName+".$table";
    ptmt = conn.prepareStatement(sql);
    ; ptmt.execute();
    }
    if(ptmt!=null){ptmt.close();}
    if(conn!=null){conn.close();}
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }

    }这个程序我是用于重命名数据库的,请问这时难道不是连接新的数据库吗

    根据这篇文章的第三种方法写的http://www.blogjava.net/xiaomage234/archive/2014/07/31/416389.html