Monday, 28 October 2013

Recover error : 1005 Can't create table 'tmp_db' (errno: 13)

While Altering table or changing Storage Engine of Database we may be got this error.
It happens probably due to Permission denied by MySQL.

less /etc/group
and then less /etc/passwd
find mysql user and group name, probably both are named mysql

change to mysql dir, probably var/lib/mysql and then type cd .. to go a dir under.

chown -R mysql:mysql ./mysql/

And also change permission of /tmp file 


By default the temporary file are directed to /tmp partition.
The permission in /tmp is different.

$ ls -ltrh /tmp
drwxr-xr-x  4 root root      4096 Jan 24 04:02 tmp


The group has no write permission on /tmp folder.

Fix :

Changed the permission of the /tmp folder and made the installation again

chmod 777 /tmp/

$ ls -ltrh /tmp

drwxrwxrwx  4 root root      4096 Jan 24 04:02 tmp


Recover Table Crash in Mysql (MYISAM ENGINE) (Got error 134 from storage engine)

Some time you can't repair table using repair command.It will show error like  "Can’t create new tempfile: ‘*.TMD file" .So we have to recover that table particular table or all tables of database.

For that you have to use the following command to do:

First go to the library file path of Mysql


/var/lib/mysql/Particular_db_name:

1.For single table recover

            myisamchk -r -f  TABLENAME.MYI
2.For ALL table recove

            myisamchk -r -f  *.MYI





Repair Table in Mysql

You will get error like Db_Name.Table_Name marked as crashed  while exporting dump to Mysql.
For that you have to manually repair table use of following command

REPAIR TABLE TABLE_NAME

Monday, 24 December 2012

Resolve problem of Could not reserve enough space for object heap


Some time you will get  Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.

It's noting you have to allocate enough Heap space for java

In Tomcat setClasspath.sh file just add below variable
export JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m -Xss2m"

In normally you can run like this also


Suppose your class is called Test in package mypackage. Run your code like this:

java -Xmx1024m mypackage.Test

In Maven  Pom.xml  set like that


<configuration>
    <maxmemory>1024M</maxmemory>
</configuration>


Batch Processing In JDBC


Batch Processing allows you to group related SQL statements into a batch and submit them with one call to the database.
When can  improving performance by send several SQL statements to the database at once and  reduce the amount of communication overhead.

Batch Processing Have Three Methods.They are

The addBatch() method of Statement is used to add individual statements to the batch. The executeBatch() is used to start the execution of all the statements grouped together.

The executeBatch() returns an array of integers, and each element of the array represents the update count for the respective update statement.

You can remove them with the clearBatch() method. This method removes all the statements you added with the addBatch() method. However, you cannot selectively choose which statement to remove.

Batching with Statement Object:
Here is a typical sequence of steps to use Batch Processing with Statment Object:

Create a Statement object using either createStatement() methods.

Set auto-commit to false using setAutoCommit().

Add as many as SQL statements you like into batch using addBatch() method on created statement object.

Execute all the SQL statements using executeBatch() method on created statement object.

Finally, commit all the changes using commit() method.

Example :


import java.sql.*;

public class JdbcExecuteStatement {

  public static void main(String args[]) {
  Connection conn = null;
  String SQL="";
  String name="fd";
  String url = "jdbc:mysql://localhost:3306/test";
  String driver = "com.mysql.jdbc.Driver";
  String user = "root";
  String pass = "root";
  try {
 Class.forName(driver);
 conn = DriverManager.getConnection(url, user, pass);
// Create statement object
 Statement stmt = conn.createStatement();
 // Set auto-commit to false
          conn.setAutoCommit(false);
 // Create SQL statement
  SQL = "INSERT INTO Abc (no, name) " +
              "VALUES(200,'Zia')";
 // Add above SQL statement in the batch.
 stmt.addBatch(SQL);
 // Create one more SQL statement
  SQL = "INSERT INTO Abc (no, name) " +
              "VALUES(201,'Raj')";
 stmt.addBatch(SQL);
  // Add above SQL statement in the batch.
   SQL = "INSERT INTO Abc (no, name) " +
              "VALUES(203,'kumar')";
 // Add above SQL statement in the batch.
 stmt.addBatch(SQL);
 // Create one more SQL statement
  SQL = "UPDATE Abc SET name='"+name+"' " +
              "WHERE no = 1";
 // Add above SQL statement in the batch.
 stmt.addBatch(SQL);
 // Create an int[] to hold returned values
 int[] count=  stmt.executeBatch();
 //Explicitly commit statements to apply changes
 //conn.commit();

  } catch (Exception e) {
  System.out.println(e);

  }
  }
}

This above  Program is insert multiple  rows and updating multiple rows at once .


Sunday, 23 December 2012

Execute Statement In JDBC


        JDBC Execute Statement is used to execute SQL Statement, The Execute Statement accept SQL object as parameter and return you the result set from a database.
        statement.execute ( ) method is used to execute the sql query. This may return you a set of row into your table of database.

Example :

import java.sql.*; 
public class JdbcExecuteStatement {
  public static void main(String args[]) {
  Connection con = null; 
  Statement st = null; 
  String url = "jdbc:mysql://localhost:3306/test";
  String driver = "com.mysql.jdbc.Driver"; 
  String user = "root"; 
  String pass = "root"; 
  try { 
  Class.forName(driver);
  con = DriverManager.getConnection(url, user, pass);
  st = con.createStatement();
  String sql = "create table Abc(no integer,name varchar(10))"; 
  st.execute(sql);

  } catch (Exception e) {
  System.out.println(e);
  } 
  } 
}  

This will create one new table Abc with colum no and name

Wednesday, 5 December 2012

Overcome Problem Couldn't get host name In Sever

While updating centos server or installing new server  we will  get error like [Red5] Couldn't get host name! org.quartz. Scheduler Exception: Couldn't get host name! [See nested exception: java.net.UnknownHostException]

It's nothing we forget to configure host name in hosts file.We can overcome these by  configuring host name in hosts file 

If you going to access locally  means just configure like this

# Do not remove the following line, or various programs

# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost




or going to access outside means you have  configure like this

# Do not remove the following line, or various programs

# that require network functionality will fail.

your static ip  host name

Ex for host name www.google.com