Welcome to my blog, hope you enjoy reading
RSS

Tuesday 5 June 2012

database and java


Changing the engine in the all tables of the database progrmetically for mysql



                     Connection connection = null;
   try{
                     //for getting the connecion  
    Class.forName("com.mysql.jdbc.Driver");  
    connection =                                                       DriverManager.getConnection("jdbc:mysql://localhost:3306/hydhouse","root","password");
         try{          
           // Create statement object
           Statement stmt = connection.createStatement();

                            //for getting the tables from that database
           DatabaseMetaData dbm = connection.getMetaData();
 String[] types = {"TABLE"};
 ResultSet rs = dbm.getTables(null,null,"%",types);
 while (rs.next()){
 String table = rs.getString("TABLE_NAME");

//for change the engine in mysql
 String sql="ALTER TABLE "+table+" ENGINE = innodb ";
 int i=stmt.executeUpdate(sql);
 System.out.println(i);
 }
       }
       catch (SQLException s){
        connection.close();
         System.out.println("SQL Exception " + s);
       }



0 comments: