Monday, 6 August 2012

SPHINX CONFIGURATION & INSTALLATION WITH POSTGRESQL DATABASE



1. Installing Sphinx on Linux platform.
Required Tools
i) a working C++ compiler. GNU gcc is known to work.
ii) a good make program. GNU make is known to work.


Postgresql devel & lib installation:
before installation check
$ whereis pg_config
   return
 pg_config: null install these tools
1. $yum install postgresql-libs
2. $yum install postgresql-devel

return
pg_config: /usr/bin/pg_config /usr/include/pg_config.h /usr/share/man/man1/pg_config.1.gz

it means "already Installed all dependencies".


Installation Steps:

1. Download Sphinx source tarball from
http://sphinxsearch.com/downloads/release/
download sphinx-2.0.5-release.tar.gz.
2.
Extract everything from the distribution tarball (haven't you already?) and
go to the sphinx sub directory. (We are using version 2.0.1-beta here for
the sake of example only; be sure to change this to a specific version you're using.

    $ tar -xzvf sphinx-2.0.4-release.tar.gz
    $cd sphinx.
3.
    Run the configuration program:
    $ ./configure
    There's a number of options to configure. The complete listing may be obtained by using --help switch. The most important ones are:
    i) --prefix, which specifies where to install Sphinx;
    such as --prefix=/usr/local/sphinx (all of the examples use this prefix)
    ii) --with-pgsql, which specifies where to look for PostgreSQL include
    and library files.
    Example:
$./configure --prefix=/usr/local/sphinx --without-mysql --with-pgsql --with-pgsql-includes=/home/PostgreSQL/8.4/include/postgresql/ --with-pgsql-libs=/home/PostgreSQL/8.4/lib/postgresql/    4. Build the binaries:
    $ make
Install the binaries in the directory of your choice:
(defaults to /usr/local/bin on *nix systems, but is overridden with configure -prefix).
$ make install

Errors:
1. ERROR: source 'addressBookSource': unknown type 'pgsql'; skipping.

Solution:
 Install postgresql libraries
1. $yum install postgresql-libs
2. $yum install postgresql-devel

2. ERROR: index 'addressBookIndex': sql_query: ERROR:  permission denied for relation addressbook



Solution:Grant all permission to table
GRANT ALL ON "tablename" TO "username"
GRANT ALL ON DATABASE "databasename" TO "username"


                                                           -PAVANKUMAR JOSHI

Thursday, 19 July 2012

Google Maps integration on Blackberry Native Application


 There is no library(API' s) for Google Maps on blackberry. First we need to install Google maps on device- link http://maps.google.com .
Google Places API doesn't support on blackberry device.
Blackberry Google maps features(Version 4.5.3)
1. Directions 2. Layers- Traffic, Satellite,Terrain,Latitude,Driving Directions,Transit Lines,My Maps.

As my research have 3 options.

Option 1: Using already installed Google maps app instance. Send some data(Location - lat/long) to
the Google Maps app instance and then have it launch/run on its application .

- Using KML (Keyhole Markup language).
Keyhole Markup Language (KML) is an XML notation for expressing geographic
annotation and visualization within Internet-based, two-dimensional maps and three-
dimensional Earth browsers. KML was developed for use with Google Earth, which was
originally named Keyhole Earth Viewer.

Syntax: <Placemark>
<name>Corner House, Jayanagar</name>
<description>Local business</description>
<styleUrl>#yellow</styleUrl>
<Point>
<coordinates>77.584929,12.9228,0</coordinates>
</Point>
</Placemark>
Two Methods to get Near by restaurants.(Places).
1. Get near by restaurants by Using Server Http Call
- From mobile send current location lat/long using HTTP call to server-
Parameter( Latitude , longitude, radius) .
- Server will scan near by restaurants lat/long using Google maps Javascript API.
- Generate KML file & send it to Mobile phone.
- Blackberry Google Maps app instance display places using KML file.

2. Get Near by restaurants using “ Facebook Graph API “
- First we need to install facebook application on handset.
- Create Access token key using this URL - http://developers.facebook.com/tools/explorer/
- Using this URL get near by restaurants details with lat/Long.



Sign up for a Google Maps Premier account and use the Static Maps API.
Google Maps API Premier supported extra Features
                                         Maps API       Maps API Premier
1. Street View                        Yes                      Yes
2. Driving direction.              Yes                      Yes
3. Advanced Geocoding.        --                        Yes
4. Larger Static Maps.            --                        Yes
5. Internal Deployments.       --                         Yes
6. Control of Advertising      --                          Yes

Option 3: Blackberry Provides Web Works API(Platform) .
- This is mainly HTML5 Framework .
- Using this API ,we can create good background and skills are in using web technologies
like HTML5, CSS and JavaScript, JQuery(Limited features).
- This platform extends some of the native device capabilities like
1. system utilities.
2. dialogs.
3. invoking other apps.
4. GPS details.
- This Platform uses device browser on application.
Google Maps:
We can use Google maps official Javascript API on this platform.

Advantages:
1. Use browser supported Google maps features using javascript API.
2. Better design – HTML5 & CSS.


Disadvantages:
1. Performance issues – Takes some seconds to load maps.

Friday, 13 July 2012

JDBC - Interview Questions(Part -II)


1. How will you retreive database warnings from a Connection object in JDBC?


//Retrieving warning from connection object
SQLWarning warning = conn.getWarnings();

//Retrieving next warning from warning object itself
SQLWarning nextWarning = warning.getNextWarning();


2. How will you retreive database warnings from a Statement object in JDBC?


//Retrieving warning from statement object
stmt.getWarnings();

//Retrieving next warning from warning object itself
SQLWarning nextWarning = warning.getNextWarning();



3. How will you retreive database warnings from a ResultSet object in JDBC?

//Retrieving warning from resultset object
rs.getWarnings();

//Retrieving next warning from warning object itself
SQLWarning nextWarning = warning.getNextWarning();


4. What does the clearWarnings() method do?

A call to clearWarnings() method clears all warnings reported for this object. After a call to this method, the method getWarnings returns null until a new warning is reported for this object.

5. What happens when I try to call the getWarning() method on a connection/statement/resultset after it has been closed?

Trying to call the getWarning() method on either of these 3 objects after they are closed will cause an SQLException to be thrown.

6. Let us say that I just closed my Statement object so, I cannot access the getWarning() on my statement. Can I still access the getWarning() on my ResultSet?

No. Closing a Statement automatically closes the ResultSet connected to it. So, you will get the same SQLException if you try to do so.

7. What is DatabaseMetaData?

JDBC API has 2 Metadata interfaces DatabaseMetaData & ResultSetMetaData. The DatabaseMetaData provides Comprehensive information about the database as a whole. This interface is implemented by driver vendors to let users know the capabilities of a Database Management System (DBMS) in combination with the driver based on JDBC technology ("JDBC driver") that is used with it. Use DatabaseMetaData to find information about your database, such as its capabilities and structure.

8. How will you use the DatabaseMetaData? Can you write a sample example code?


DatabaseMetaData md = conn.getMetaData();
System.out.println("Database Name: " + md.getDatabaseProductName());
System.out.println("Database Version: " + md.getDatabaseProductVersion());
System.out.println("Driver Name: " + md.getDriverName());
System.out.println("Driver Version: " + md.getDriverVersion());


9. What is ResultSetMetaData?

JDBC API has 2 Metadata interfaces DatabaseMetaData & ResultSetMetaData. The ResultSetMetaData is an object that can be used to get information about the types and properties of the columns in a ResultSet object. Use ResultSetMetaData to find information about the results of an SQL query, such as size and types of columns.

10. How will you use the ResultSetMetaData? Can you write a sample example code?


ResultSet rs = stmt.executeQuery("SELECT * FROM TABLE_NAME");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
boolean b = rsmd.isSearchable(1);



11. What is rowset?

A RowSet is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet.

12. Why do we need a RowSet?

RowSet is a interface that adds support to the JDBC API for the JavaBeans component model. A rowset, which can be used as a JavaBeans component in a visual Bean development environment, can be created and configured at design time and executed at run time. The RowSet interface provides a set of JavaBeans properties that allow a RowSet instance to be configured to connect to a JDBC data source and read some data from the data source. A group of setter methods (setInt, setBytes, setString, and so on) provide a way to pass input parameters to a rowset's command property. This command is the SQL query the rowset uses when it gets its data from a relational database, which is generally the case. Rowsets are easy to use since the RowSet interface extends the standard java.sql.ResultSet interface so it has all the methods of ResultSet

13. What are the advantages of using RowSet over ResultSet?

There are two clear advantages of using RowSet over ResultSet:

* RowSet makes it possible to use the ResultSet object as a JavaBeans component.
* RowSet be used to make a ResultSet object scrollable and updatable. All RowSet objects are by default scrollable and updatable. If the driver and database being used do not support scrolling and/or updating of result sets, an application can populate a RowSet object implementation (e.g. JdbcRowSet) with the data of a ResultSet object and then operate on the RowSet object as if it were the ResultSet object.

14. What are the different types of RowSet ?
There are two types of RowSet are there. They are:
* Connected - A connected RowSet object connects to the database once and remains connected until the application terminates.
* Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.

15. Can you give an example of Connected RowSet?

A JdbcRowSet object is a example of connected RowSet, which means it continually maintains its connection to a database using a JDBC technology-enabled driver.

16. Can you give an example of Disconnected RowSet?

A CachedRowSet object is a example of disconnected rowset, which means that it makes use of a connection to its data source only briefly. It connects to its data source while it is reading data to populate itself with rows and again while it is propagating changes back to its underlying data source. The rest of the time, a CachedRowSet object is disconnected, including while its data is being modified. Being disconnected makes a RowSet object much leaner and therefore much easier to pass to another component. For example, a disconnected RowSet object can be serialized and passed over the wire to a thin client such as a personal digital assistant (PDA).

17. What are the benefits of having JdbcRowSet implementation?

The JdbcRowSet implementation is a wrapper around a ResultSet object that has following advantages over ResultSet
* This implementation makes it possible to use the ResultSet object as a JavaBeans component. A JdbcRowSet can be used as a JavaBeans component in a visual Bean development environment, can be created and configured at design time and executed at run time.
* It can be used to make a ResultSet object scrollable and updatable. All RowSet objects are by default scrollable and updatable. If the driver and database being used do not support scrolling and/or updating of result sets, an application can populate a JdbcRowSet object with the data of a ResultSet object and then operate on the JdbcRowSet object as if it were the ResultSet object.

18. What is the need of BatchUpdates feature in JDBC?

The BatchUpdates feature allows us to group SQL statements together and send to database server in one single shot instead of multiple calls.

19. What is a DataSource?

A DataSource object is the representation of a source of data in the Java programming language.

In basic terms:
* A DataSource is a facility for storing data.
* DataSource can be referenced by JNDI.
* Data Source may point to RDBMS, file System , any DBMS etc..

Typically in enterprise application perspective, the term DataSource can be used interchangeably with a RDBMS database because in almost all cases, our DataSource will be pointing to an RDBMS database.

20. What are the advantages of DataSource?

The few advantages of using data source are :
* An application does not need to hardcode driver information, as it does with the DriverManager.
* The DataSource implementations can easily change the properties of data sources. For example: There is no need to modify the application code when making changes to the database details.
* The DataSource facility allows developers to implement a DataSource class to take advantage of features like connection pooling and distributed transactions.

21. What is the difference between a Statement and a PreparedStatement?

Some of the main differences between a statement & PreparedStatement are:


Statement PreparedStatment
A standard Statement is used to create a Java representation of a literal SQL statement and execute it on the database. A PreparedStatement is a precompiled statement. This means that when the PreparedStatement is executed, the RDBMS can just run the PreparedStatement SQL statement without having to compile it first.
Statement has to verify its metadata against the database every time. A prepared statement has to verify its metadata against the database only once.
If you want to execute the SQL statement once go for STATEMENT If you want to execute a single SQL statement multiple number of times, then go for PREPAREDSTATEMENT. PreparedStatement objects can be reused with passing different values to the queries.
22. What’s the difference between TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE in ResultSets?

Some of the main differences between a TYPE_SCROLL_INSENSITIVE & TYPE_SCROLL_SENSITIVE are:

TYPE_SCROLL_INSENSITIVE TYPE_SCROLL_SENSITIVE
An insensitive resultset is like the snapshot of the data in the database when query was executed. A sensitive resultset does NOT represent a snapshot of data, rather it contains points to those rows which satisfy the query condition.
After we get the resultset the changes made to data are not visible through the resultset, and hence they are known as insensitive. After we obtain the resultset if the data is modified then such modifications are visible through resultset.
Performance not effected with insensitive. Since a trip is made for every ‘get’ operation, the performance drastically get affected.