Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is the current version of JDBC? and explain its
features?

Answer Posted / dinesh

The current version of JDBC is JDBC 4:
1.SQL 2003support.
2.XML as a First-Class SQL Data Type.
3.Using JDBC 4's SQLXML data type, you could retrieve a
user's blog.
4.Exceptional exceptions:
5,Type-safe querying and results:


In details about above one:
1.SQL 2003support
Connection c = myDataSource.getConnection();
PreparedStatement st = c.prepareStatement("insert into
siteusers (userid, username) values
(?, ?);
st.setRowId(1, rowId1);

When creating a new BLOB or CLOB object through
Connection's appropriate create() method,

the resulting object does not contain the actual binary or
character data. Rather, you would add

the "real" data to the CLOB or BLOB objects:

Connection c = myDataSource.getConnection();
Blob myBlob = c.createBlob();
OutputStream outStream = myBlob.setBinaryStream(0);

2.XML as a First-Class SQL Data Type
create table user_has_blog(userid int, blog_entry xml);

3.Using JDBC 4's SQLXML data type, you could retrieve a
user's blog entries as follows:
Connection c = myDataSource.getConnection();
PreparedStatement st = c.prepareStatement("select userid,
blog_entry from user_has_blog");
ResultSet rs = st.executeQuery();
while (rs.next()) {
SQLXML blog = st.getSQLXML("blog_entry");
javax.xml.stream.XMLStreamReader reader =
blog.createXMLStreamReader();
blog.free();
}

SQLXML's createXMLStreamReader() returns a StAX stream
reader, which is a low-level interface

allowing access to an XML stream . See the reference at
the end of this article about using StAX

to read and write XML data. Whenever you've exhausted the
XML stream, you need to invoke

close() on SQLXML to free resources associated with the XML
data stream.

.The following SQL selects all users with their first and
last names into XML User elements:
create table user (int userid, firstname varchar(128),
lastname varchar(128))
select e.userid,
XMLELEMENT(NAME
"user", e.firstname || e.lastname) as "result" from
employee e;


Creating and inserting into the database a new SQLXML value
is similar to working with BLOBs.

You invoke Connection's createSQLXML() method, and then
populate the resulting SQLXML's

input stream with the XML content:

Connection c = myDataSource.getConnection();
PreparedStatement st = c.prepareStatement("insert into
user_has_blog (userid, blog_entry)

values (?, ?)");
SQLXML blogEntry = c.createSQLXML();
Writer writer = blogEntry.createXMLSteamWriter();
//write XML content to writer
st.setInt(1, 1); //User id
st.setSQLXML(2, blogEntry)


4.Exceptional exceptions:
In JDBC4:SQL Exception has getNextException() and getCasuse
() methods
The method getNextException() :returns either the next
Exception in the exception chain, or null,

when the root of the hierarchy is reached.
The method getCasuse() : return a non-SQLException subtype
SQLTransientException :SQLTransientConnectionException,SQLTi
meoutException

,SQLTransactionRollbackException

SQLNonTransientException:SQLDataException

,SQLIntegrityConstraintViolationException,SQLInvalidAuthoriz
ationSpecException

,SQLNonTransientConnectionException ,SQLSyntaxErrorException


5,Type-safe querying and results:
Consider the class
class User {
int userID;
String name;
String department;
}


Consider the Table:
create table user (int userid, name varchar(128),
department varchar(128));

Template Class
class MyQueries {
public static final String SELECT_ALL_USERS
= "select * from user";
}


interface MyQueries extends BaseQuery {

@Query(sql="select * from user")
DataSet getAllUsers();
}

You are obtain an instance of MyQuery from the Connection
class:
DataSource myDataSource = new DataSource();
Connection c = myDataSource.getConnection();
MyQueries myQueries = c.createQueryObject(MyQuery.class);
DataSet users = myQueries.getAllUsers();
for (User u: users) {
System.out.println("User's name is: " + user.name;
}

//For ex getting dep details
interface MyQueries extends BaseQuery {

@Query(sql="select * from user where department=
{department}")
DataSet getDepartmentUsers(String department);
}

//For update query
interface MyQueries extends BaseQuery {

@Update(sql="update user set department={deparment}
where name= {userName}")
int updateDeparment(String userName, String
department);
}
Dataset allows you to insert and update data in the
database.
Connection c = myDataSource.getConnection();
MyQueries q = c.createQueryObject(MyQueries.class);
DataSet users = q.create();
User user = new User();
user.setUserID(1);
user.setName("Joe");
user.setDeparment("Accounting");
users.insert(user);


This are the advantage in JDBC 4 new version.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why can't I invoke the ResultSet methods afterLast and beforeFirst when the method next works?

1150


What isolation level is used by the DBMS when inserting, updating and selecting rows from a database?

930


Explain the necessary steps to connect to the database in java?

995


What does jdbc do?

969


What is type 4 jdbc driver?

811


What is a java driver?

947


What are the differences between setmaxrows(int) and setfetchsize(int)?

1025


What is odbc jdbc?

966


How do I connect to jdbc?

888


Can we have foreign key reference to a non primary key column ?

923


What is the purpose of jdbc?

992


How can we retrieve data from the resultset?

924


explain about special characters?

936


What is the benefit of having jdbcrowset implementation? Why do we need a jdbcrowset like wrapper around resultset?

917


How MS-Access DB can be accessed over a network, using JDBC API?

2394