View RSS Feed

Java Database

  1. Executing PreparedStatement Objects

    by , 03-10-2012 at 08:03 AM
    • Execute statement shall be called for execution of a PreparedStatement Object.
    • The executeQuery when just 1 ResultSet is returned by query,
    • The executeUpdate when no ResultSet is returned by query.
    • The execute when one or more than one ResultSet object return by query.

    Call of “execute update” method is explained by this code.
    Java Code:
    updateSales.setInt(1, e.getValue().intValue());
    updateSales.setString(2, e.getKey());
    updateSales.executeUpdate();
    updateTotal.setInt(1,
    ...
    Categories
    JDBC
  2. Categorized SQLExceptions

    by , 03-10-2012 at 08:01 AM
    JDBC driver shall throw SQLException subclass, which presents a common error state or common SQLState. They are not linked to any specified SQLState calss value.

    Portable error handling codes are written by its help.

    These exceptions given are the sub-classes of 1 of the given classes.

    • SQLNonTransientException
    • SQLRecoverableException
    • SQLTransientException
    Categories
    JDBC
  3. Retrieving Warnings

    by , 03-10-2012 at 08:00 AM
    The SQLWarning objects are subclasses of SQLException. They are involved in dealings with database access warnings. Warning actually doesn’t stop the execution of program, as oppose to exceptions. They inform users that few things which are not present in execution plan are happening.

    E.g:
    • A privilege revoked didn’t revoke.
    • An error occurred, during the requested disconnections.


    A warning might be on:
    • A connection object
    • A ResultSet object
    • A
    ...
    Categories
    JDBC
  4. Retrieving Exceptions

    by , 03-10-2012 at 07:58 AM
    The given code outputs the following that is contained in the SQLException or other exception which have been chained to it:
    • SQL State
    • Error description
    • Error Code
    • Cause

    Java Code:
    public static void
        printSQLException(SQLException ex) {
        for (Throwable e : ex) {
            if (e instanceof SQLException) {
                if (ignoreSQLException(
                    ((SQLException)e).
                    getSQLState()) == false)
    ...
    Categories
    JDBC
  5. Overview of SQLException

    by , 03-10-2012 at 07:57 AM
    Opposed to Exception, SQL Exception’s instance is thrown when an error occurs with JDBC while doing communication with data source. Data source is the database presentation to which connection is been made to an application.

    Error’s root cause is determined by the useful information that is given in SQLException.

    • An error’s description: Method SQLException.getMessage() returns the string, which details the error.
    • A SQL state code. Codes are ISO/ANSI standardized.
    ...
    Tags: sqlexception Add / Edit Tags
    Categories
    JDBC
  6. Advantages of DataSource Objects

    by , 03-10-2012 at 07:56 AM
    A DataSource object is considered a good alternative of class “DriverManager” and is most preferable to be used as it creates a database connection. There is no need to hard code the JDBC URL or driver name in application while using DataSource object. Such approach is loosely coupled & more portable.

    When there is a need to do alterations then changes might be done in properties file by the admin and no code changes of ever application is needed, which is involved in its implementation. ...
    Categories
    JDBC
  7. Using DataSource Objects to Get a Connection

    by , 03-10-2012 at 07:54 AM
    Classes instantiate object which implement Datasource. This presents particular some data source like a file, or DBMS.

    A particular DBMS is presented by a DataSource object. For more than 1 data source usage, it is required to have separate DataSource objects for every data source. There are 3 ways for implementation of the DataSource interface.

    • Standard Connection objects are produced by the implementation of basic DataSource. These objects are not used or pooled
    ...
    Categories
    JDBC
  8. MySQL Connector/J Database URL

    by , 03-10-2012 at 07:52 AM
    For MySQL Connector/J, the database connection URL syntax is given below:

    jdbc:mysql://[host][,failoverhost...]
    [:port]/[database]
    [?propertyName1][=propertyValue1]
    [&propertyName2][=propertyValue2]...

    • host: Port is host’s name & port no. of that computer which host database. Port and host default values are 3306 and 127.0.0.1 , if not specified,
    • database is database name to connect. Without default database connection is
    ...
    Categories
    JDBC
  9. MySQL Connector/J Database URL

    by , 03-10-2012 at 07:51 AM
    For MySQL Connector/J, the database connection URL syntax is given below:

    jdbc:mysql://[host][,failoverhost...]
    [:port]/[database]
    [?propertyName1][=propertyValue1]
    [&propertyName2][=propertyValue2]...

    • host: Port is host’s name & port no. of that computer which host database. Port and host default values are 3306 and 127.0.0.1 , if not specified,
    • database is database name to connect. Without default database connection is
    ...

    Updated 03-10-2012 at 07:53 AM by Java Database

    Categories
    JDBC
  10. Java DB Database Connection URLs

    by , 03-10-2012 at 07:49 AM
    For Java DB, here is the given database connection URL syntax:

    jdbc:derby:[subsubprotocol:][databaseName]
    [;attribute=value]*

    • subsubprotocol makes Java DB specific to search in class path, database, directory, memory or in JAR file. Typically it is omitted.
    • databaseName is the database name to connect.
    • attribute=value presents semicolon-separated optional attributes list. Such attributes make you able to give instructions to Java DB so that to perform
    ...
    Categories
    JDBC
  11. Using the DriverManager Class

    by , 03-10-2012 at 07:47 AM
    The “DriverManager” class provides a method “DriverManager.getConnection” that is called when connection to your DBMS. The following code explains the use of getConnection method.
    Java Code:
    public Connection getConnection()
        throws SQLException {
        Connection conn = null;
        Properties connectionProps = new Properties();
        connectionProps.put("user", this.userName);
        connectionProps.put("password", this.password);
    ...
    Categories
    JDBC
  12. Establishing a Connection

    by , 03-10-2012 at 07:44 AM
    The very 1st step to use data source is to make connection with data source. Data source could be:
    • Legacy file system
    • DBMS
    • Few other data sources, with a corresponding JDBC driver


    For connecting an application to data source, these 2 classes are used.

    • DriverManager: Complete implementation is provided by this class so that to make a connection b/w application and a data source, that is specified by URL of database. JDBC drivers are automatically loaded
    ...
    Categories
    JDBC
  13. Closing Connections

    by , 03-10-2012 at 07:43 AM
    Method Statement.close shall always be called to release resources instantly that are in use when usage of a statement gets finished. To close ResultSet object, call Statement.close method.

    For closing all resources or release the memory present in Java program, finally block is used.

    Given piece of code details how a statement is closed in the finally block present in your program.
    Java Code:
    } finally {
        if (stmt != null) { stmt.close(); }
    }
    ...
    Categories
    JDBC
  14. Processing ResultSet Objects

    by , 03-10-2012 at 07:42 AM
    Data that has been store in a ResultSet is accessed by a cursor. In ResultSet object, one row of data is pointed by the help of this cursor. In beginning, before 1st row the pointer gets positioned. Different methods are provided by the ResultSet objects so that to move the cursor.

    Given code details the ResultSet object processing.
    Java Code:
    try {
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
    ...
    Categories
    JDBC
  15. Executing Queries

    by , 03-10-2012 at 07:40 AM
    Execute method is called from statement for execution of a query.
    • execute: In case when 1st object which query returns is ResultSet, returns true. This method is used when one or more than one ResultSet objects are returned by query. ResultSet objects are retrieved that have been returned from query, by calling Statement.getResultSet repeatedly.
    • executeQuery: One ResultSet object is retuned.
    • executeUpdate: An integer is returned which presents the rows that have been affected by SQL
    ...
    Categories
    JDBC
  16. Creating Statements

    by , 03-10-2012 at 07:39 AM
    A Statement interface presents a SQL statement. Generations of the ResultSet objects take place in response of the execute Statement objects. ResultSet is a data table which presents the database result set.
    To make Statement object, a connection object is needed. To create statement, consider this code:
    Stmt = con.createStatement();

    The following are the three different kinds of statements.
    • Statement: Simple SQL statements are implemented by it without any
    ...
    Categories
    JDBC
  17. JDBC Product Components

    by , 03-10-2012 at 07:38 AM
    Following four components are included in JDBC:
    • The JDBC API: From Java programming languages, access is provided to relational databases by JDBC API. Following could be performed by JDBC API.

    o Retrieves the results
    o Execution of SQL Statements
    o Propagate alterations back to the data sources
    o Interaction with various data sources, in a distributed environment.

    • JDBC Driver Manager: DriverManager class of JDBC provides connections b/w JDBC
    ...
    Categories
    JDBC
  18. JDBC Introduction

    by , 03-10-2012 at 07:36 AM
    JDBC API being a java base API, it accesses stored data and tabular data present in relational database. Java applications are written by the help of JDBC API. They are helpful to manage these programming activities, given below:
    • To a data source, connect like a database
    • Send updated statements & database queries.
    • Bring records of database & do processing of these records that have been received from the database.


    The given code details the above 3 steps. ...
    Categories
    JDBC
  19. JDBC drivers

    by , 03-10-2012 at 07:35 AM
    Kinds of drivers provided by JDBC are also known as client side adapters. At the client’s machines, such drivers are installed. Request conversions from Java programs into protocol are done by them which are understandable by DBMS.

    Commercial as well as free drivers are present for most of the databases so that they could be used along with the Java programs. Such drivers come in these given categories.

    • Type 1: Native code of ODBC driver which is locally available
    ...
    Tags: jdbc drivers Add / Edit Tags
    Categories
    JDBC
  20. JDBC Functionality

    by , 03-10-2012 at 07:33 AM
    Various implementations are there for JDBC that are used by same application. Mechanism is provided by API:
    • Dynamically correct Java packages are loaded
    • Registration with the JDBC Driver Manager


    JDBC driver manager, being a connection factory is used for creation of JDBC connections.

    Following is supported by JDBC connections:
    • Creating statements
    • Update statements
    • Executing statements
    • Stored procedure is invoked by using the JDBC Connection.
    ...
    Categories
    JDBC
  21. JDBC Key Features

    by , 03-10-2012 at 07:30 AM
    Key features of the JDBC API are:
    • Full Access to Metadata: Sophisticated application development is enabled by JDBC API, by providing metadata access. Underlying facilities and database connections capabilities are required to be understood by using metadata.
    • No Installation: No installation is needed along with usage of pure JDBC technology
    • Database Connection Identified by URL: Internet standard URLs advantage is exploited by JDBC technology to identify database connection. Data
    ...
    Categories
    JDBC
  22. Advantages of JDBC Technology

    by , 03-09-2012 at 07:35 PM
    JDBC Technology offers these given advantages.

    Leverage Existing Enterprise Data: Businesses or users are not been locked to a particular architecture. Installed databases can be used with JDBC technology to access information with ease. Even if they are stored at other databases, even then they have access for usage.

    Simplified Enterprise Development: Development of application has become an easier task which is also cost effective along with JDBC API & Java API. ...
    Categories
    JDBC
  23. JDBC Architecture

    by , 03-09-2012 at 07:33 PM
    The JDBC API consist of these 2 major interfaces sets:
    • JDBC API, for application writers
    • JDBC driver API, for driver writers


    JDBC drivers fall in 1 of the four given categories. Given figure shows that applets & applications access databases through JDBC API, by using pure Java JDBC driver.

    Name:  1.JPG
Views: 2514
Size:  11.5 KB
    JDBC Architecture

    JDBC calls are converted by such kind of drivers to network protocol. This allows client machines ...
    Categories
    JDBC
  24. The Java Database Connectivity (JDBC)

    by , 03-09-2012 at 07:31 PM
    Java Database Connectivity JDBC API is considered to be a database’s industry standard. An independent connectivity is provided by it b/w range of databases and Java programming language. Like
    • Tabular data sources e.g. flat files and spreadsheet.
    • SQL databases


    To access SQL based database, call level API is provided by JDBC API.

    In Java programming language, JDBC technology is used to “write once, Run Anywhere” capabilities. This is done for those applications ...
    Tags: jdbc Add / Edit Tags
    Categories
    JDBC
  25. SQL Metadata

    by , 03-09-2012 at 07:30 PM
    Users and database information is stored itself in databases. Majority of DBMS consist of s set of system tables, which lists:
    • Tables in the database
    • Primary keys
    • Foreign keys
    • Column names in each table
    • Stored procedures



    Database features and table layout information is obtained by DBMS which consists of its own functions. Interface DatabaseMetaData is provided by the JDBC that shall be implemented by a driver writer. This is done information regarding DBMS ...
    Tags: sql metadata Add / Edit Tags
    Categories
    SQL
  26. SQL Transactions

    by , 03-09-2012 at 07:29 PM
    In a database, at the same time two users might be accessing the similar data. E.g if one user is reading column’s value from database and other one is updating column at the same time. This is possible that 1st user may get old & update data, at the same time.
    To prevent these situations, transactions are provided by DBMS so that to maintain data in persistent state. More than 1 user may access database with data concurrency, at the same time.

    More than 1 SQL statements ...
    Categories
    SQL
  27. Result Sets and Cursors

    by , 03-09-2012 at 07:28 PM
    Conditions of a query are satisfied by the result set. Result set is considered to be rows set. A result set can return no. of rows.
    • Zero
    • One
    • Many


    One user might obtain 1 row at one time. This functionality is supported by the cursor.
    Pointer and cursor are same which are present in a file that consists of many rows of the result set. Rows track is maintained by the pointer, which are accessible by the program. All rows top to bottom access is supported by a cursor, ...
    Categories
    SQL
  28. SELECT Statements

    by , 03-09-2012 at 07:27 PM
    SQL is considered to be a query language which has been designed for using it with relational databases. Standard SQL commands set is present which is used along with all relational DMS i.e. database management system. All relational DBMS use select statement.

    Information is obtained from a table by select statement. This is also known as a query. Following is specified by it.
    • 1 or more columns
    • Selection criteria
    • 1 or more tables


    First & last names ...
    Categories
    SQL
  29. Integrity Rules

    by , 03-09-2012 at 07:26 PM
    It shall be ensured by the relational tables that data is always accessible and accurate. To do this, implementation of the integrity rules is required. These rules shall be followed.
    • There shall be uniqueness in a table’s rows.
    • Correct results are not found easily and accessing data might result into certain issues. This happens when duplicate rows are present.


    Rules can be applied by user in most DBMS that duplicated rows are not permitted. In those cases, the insertion ...
    Categories
    SQL
  30. What Can SQL do?

    by , 03-09-2012 at 07:25 PM
    • Against a database, queries can be executed by SQL.
    • From a database, data can be retrieved by SQL.
    • In a database, records can be inserted by SQL.
    • In a database, records can be updated by SQL.
    • From a database, records can be deleted by SQL.
    • New databases are created by SQL.
    • In a database, new tables are created by SQL.
    • In a database, stored procedures can be created by SQL.
    • In a database, views are created by SQL.
    • SQL can set permissions at procedures, views and tables.
    Categories
    SQL
Page 1 of 2 12 LastLast