View RSS Feed

JDBC

Java Database Connectivity

  1. Retrieving auto generated key (JDBC 3.0)

    by , 11-28-2011 at 07:41 PM (My Java Tips)
    JDBC 3.0 introduces a lot of interesting and exciting features which makes database programming simpler. In this post, I will address how to retrieve auto generated keys using JDBC 3.0.


    To get the key, simply specify in the statement's execute() method an optional flag denoting that you are interested in the generated value. Flags of your interest are: Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS. Execute the statement and now you can obtain the values of the generated ...
    Categories
    JDBC
  2. Returning multiple results (JDBC 3.0)

    by , 11-28-2011 at 07:38 PM (My Java Tips)
    If you have worked with JDBC 2, you might be knowing that if your statement is returning multiple results, only one ResultSet can be opened at a time. This is a limitation. Good new is that JDBC 3.0 specification allows the Statement interface to support multiple open ResultSets. Lets see hot this can be done.



    Please note that the execute() method closes any ResultSets that were opened from a previous call. To support multiple open results, the Statement interface adds an ...
    Categories
    JDBC
  3. Prepared statement pooling (JDBC 3.0)

    by , 11-28-2011 at 07:35 PM (My Java Tips)
    JDBC 3.0 provides improved connection pooling. This post is all about that.



    It is also possible to pool prepared statements. A prepared statement allows us to keep frequently used SQL statement in a pre-compile form, thus improving performance if that statement is executed multiple times. But there is a dark side of this. Creating a PreparedStatement object introduces a certain amount of overhead. There are some developers sometimes change their object models to increase the ...
    Categories
    JDBC
  4. Transaction savepoints (JDBC 3.0)

    by , 11-28-2011 at 07:32 PM (My Java Tips)
    JDBC 2 provides complete transaction rollback control over transaction. But if you want to rollback to a point, you cannot do so. JDBC 3.0 introduces savepoints which makes this possible.


    JDBC 3.0 provides more control over transactions using savepoints. The Savepoint interface allows us to partition a transaction into logical breakpoints. This in turn provides control over how much of the transaction we wish to rolled back.

    Lets see how to do this. Review the following ...
    Tags: jdbc 2, savepoint Add / Edit Tags
    Categories
    JDBC
  5. Using PostgreSQL JDBC driver

    by , 11-12-2011 at 06:45 PM (My Java Tips)
    PostgreSQL is a popular open source object-relational database management system that is being used for small and medium sized applications. We have two options to connect to PostgreSQL. One is to use odbc/jdbc connection and the other is to use PostgreSQL JDBC driver. In this post, I will write about how to use PostgreSQL JDBC driver to connect to PostgreSQL database.


    First of all, you will need PostgreSQL database driver. It can be downloaded from
    http://jdbc.postgresql.org/download.html ...
    Categories
    JDBC
  6. Using PreparedStatement

    by , 11-12-2011 at 06:36 PM (My Java Tips)
    SQL statements are executed on a database tables using Statement object. If the sql statement takes parameter, then it is a wise decision to use PreparedStatement as they are more flexible and makes coding easier.


    Creating SQL statements that take parameters provides flexible statements to work with. We can use the same statement and supply it with different values each time we execute it.

    We use place holders (question marks) in the query, which are supplied values ...
    Categories
    JDBC
  7. Calling stored procedures

    by , 11-12-2011 at 06:21 PM (My Java Tips)
    Stored procedures contain set of SQL statements and are stored on the database server. Their query execution plan is already define, so they run faster and improve the performance. In this post, I will talk about how to call stored procedures.


    An object of CallebleStatement (extends PrepareStatement) is used to execute store procedures. PrepareCall() method is use to create CallebleStatementís object.

    Java Code:
    CallebleStatement cst;
    Cst = conn.prepareCall(ď{call
    ...
  8. Types of JDBC drivers

    by , 11-11-2011 at 06:44 PM (My Java Tips)
    There are 4 different types of JDBC drivers that can be used in Java database applications. Which driver to use, depends on the requirements and available resources. I will briefly talk about each driver.


    Type 1 is JDBC-OBC bridge driver. It is pure Java and is include in java.sql.*. The client needs ODBC driver manager and ODBC driver for data source. It is ideal in situations, when ODBC driver is available for the database and is already installed on the client machine.
    ...
  9. Batch updates

    by , 11-11-2011 at 06:41 PM (My Java Tips)
    Updating a record from Java using executeUpdate() method of Statement object is used commonly by JDBC programmers. Thing to note is that this is a costly activity in terms of time, as a database trip is made. As a programmer/developer, our aim should be to write efficient Java code. In this post, I will write about how you can efficiently make several updates.


    Batch update allows us to execute several update statements in a batch. It means only one database trip will be make, thus ...
    Categories
    JDBC
  10. Connectiong To MS Access And Fetching Records

    by , 11-08-2011 at 07:37 PM (My Java Tips)
    JDBC (Java Database Connectivity) is designed to allow user to use SQL(Structured Query Language) to query databases. JDBC makes our tasks easy as it handles all low-level concerns about particular database types. It allows you to query an Access database with exactly the same source code as with an Oracle database.

    JDBC is similar to Microsoft's ODBC with the plus point "Platform Independence". To use JDBC, you need to have database driver to communicate with the database. ...
    Tags: jdbc, sql Add / Edit Tags
    Categories
    JDBC
  11. Using prepaid statements

    by , 10-30-2011 at 06:22 PM (My Java Tips)
    SQL statements are executed on a database tables using Statement object. If the sql statement takes parameter, then it is a wise decision to use PreparedStatement as they are more flexible and makes coding easier.


    Creating SQL statements that take parameters provides flexible statements to work with. We can use the same statement and supply it with different values each time we execute it.
    We use place holders (question marks) in the query, which are supplied values to make ...
    Categories
    JDBC
  12. Using Batches in JDBC

    by , 10-30-2011 at 06:18 PM (My Java Tips)
    Updating a record from Java using executeUpdate() method of Statement object is used commonly by JDBC programmers. Thing to note is that this is a costly activity in terms of time, as a database trip is made. As a programmer/developer, our aim should be to write efficient Java code. In this post, I will write about how you can efficiently make several updates.


    Batch update allows us to execute several update statements in a batch. It means only one database trip will be make, thus ...
    Categories
    JDBC