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

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);
        }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: