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

Answers were Sorted based on User's Feedback



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

Answer / koundinya_1993

JDBC 4.0,
Some of the new set of features which come along with
Mustang is JDBC 4.0 are:

No need for Class.forName("DriverName")

Changes in Connection and Statement Interface

Better Pools

Using ResultSet Becomes More Flexible

More APIs Become Available

Is This Answer Correct ?    6 Yes 1 No

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

Answer / 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

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

Answer / naresh katakam

JDBC 6.0

features:
No need for Class.forName("DriverName")


The three most important features of Driver and Connection
Management in JDBC are described below with some new
features and enhancements.

1. Getting Connected Becomes Easier


Using ResultSet Becomes More Flexible
More APIs Become Available:

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More JDBC Interview Questions

What are the different classes through which JDBC represents statements?

0 Answers  


How do we load the drivers?

0 Answers  


Is jdbc object oriented?

0 Answers  


how to prevent finally block from execution

4 Answers   Bosch,


What is the use of prepared statement?Ans:used to execute pre compiled statement...so the question is when that precompiled statement will be execute or comiple?................

6 Answers   TCS,






What are types of resultset?

0 Answers  


What is the difference between setmaxrows(int) and setfetchsize(int)?

0 Answers  


Explain the main method?

0 Answers  


How a database driver can be loaded with jdbc 4.0 / java 6?

0 Answers  


How do I stop nullpointerexception?

0 Answers  


How can I connect mysql or oracle with java?

0 Answers  


Why did my jdbc code throw a rollback sqlexception?

0 Answers  


Categories