public class JAVADB2
 {
   public static void main(String args[]) throws SQLException 
   {	
     try	
     {
	Connection conn = null;		
	ResultSet  rs 	= null;
	Statement  stmt	= null;
			
	String strSQL = "SELECT * FROM employee";
	conn = incDB.getConnection();
	stmt = (Statement)conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.FETCH_FORWARD);			
			
 	rs = stmt.executeQuery(strSQL);			
	display.getRecords(rs);
      } 
      catch (SQLException e) 
      {
	incDB.getException(e);
      }
    }	
}
Utility Methods
 public class incDB
{	
	private static String USER_NAME = "root";
	private static String USER_PASS = "pass";
	private static String CONN_STRING = "jdbc:mysql://localhost/test";
	
	public static Connection getConnection() throws SQLException
	{
		return DriverManager.getConnection(CONN_STRING, USER_NAME, USER_PASS);
	}
	
	public static void getException(SQLException e)
	{
		System.out.println("Message :"+e.getMessage());
		System.out.println("Error Code :"+e.getErrorCode());
		System.out.println("State : "+e.getSQLState());
	}
}

public class incDB
{	
	private static String USER_NAME = "root";
	private static String USER_PASS = "";
	private static String CONN_STRING = "jdbc:mysql://localhost/test";
	
	public static Connection getConnection() throws SQLException
	{
		return DriverManager.getConnection(CONN_STRING, USER_NAME, USER_PASS);
	}
	
	public static void getException(SQLException e)
	{
		System.out.println("Message :"+e.getMessage());
		System.out.println("Error Code :"+e.getErrorCode());
		System.out.println("State : "+e.getSQLState());
	}
}

Leave a reply