Powered by Blogger.

Thursday, 18 September 2014

Sql

By Unknown  |  08:57 No comments


What's the difference between "PreparedStatement" and "Statement"?
PreparedStatements are useful when you have one query to execute several times with just parameters changed. In normal case each and every query has to be checked by database whether syntax is ok or not. SQL Statement are precomplied and stored in PreparedStatement object, so it saves time of database to check its syntax.
        The PreparedStatement is a slightly more powerful version of a Statement, and should always be at least as quick and easy to handle as a Statement.
  1. Parse the incoming SQL query
  2. Compile the SQL query
  3. Plan/optimize the data acquisition path
  4. Execute the optimized query / acquire and return data
A Statement will always proceed through the four steps above for each SQL query sent to the database. A PreparedStatement pre-executes steps (1) - (3) in the execution process above. Thus, when creating a PreparedStatement some pre-optimization is performed immediately. The effect is to lessen the load on the database engine at execution time.
The other strength of the PreparedStatement is that you can use it over and over again with new parameter values, rather than having to create a new Statement object for each new set of parameters. This approach is obviously more efficient, as only one object is created.
Use the set methods each time to specify new parameter values.

What information is needed to create a TCP Socket? 

The Local Systems IP Address and Port Number. And the Remote System’s IPAddress and Port Number.

What are stored procedures? How is it useful? 

A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements every time a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL pre-processor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procedures to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procedures provide a mechanism to do these manipulations. Stored procedures are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases.

What Class.forName will do while loading drivers? 

It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.

How to Retrieve Warnings? 
SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object. 

SQLWarning warning = stmt.getWarnings();
if (warning != null)
{
    while (warning != null)
      {
          System.out.println(\"Message: \" + warning.getMessage());
          System.out.println(\"SQLState: \" + warning.getSQLState());
          System.out.print(\"Vendor error code: \");
          System.out.println(warning.getErrorCode());
          warning = warning.getNextWarning();
  }

}

Difference between the following in java System.exit(0);System.exit(-1);System.exit(1);
Zero=Everything Okay
Positive=Something I expected to go wrong went wrong (bad command-line, can't find file, could not connect to server)

Negative=Something I didn't expect went wrong (system error - unanticipated exception - externally forced termination e.g. kill -9)


















Author: Unknown

Hello, I am Author, decode to know more: In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet.

0 comments:

Recent Articles

© 2014 Learning Java. WP themonic converted by Bloggertheme9. Published By Gooyaabi Templates
TOP