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

Explain the different ways to register a driver?

2 Answers  


What is the syntax of URL to get connection?

1 Answers  


How do we call a stored procedure from jdbc?

0 Answers  


What is jdbc driver in java?

0 Answers  


What is JDBC?

3 Answers   Akamai Technologies,






MY code is: public class P1{ public static void main(String ar[]) { class.forName("java.lang.String"); } } errors i got are :New.java:5: error: <identifier> expected class.forName("java.lang.String"); ^ New.java:5: error: invalid method declaration; return type required class.forName("java.lang.String"); ^ New.java:5: error: illegal start of type class.forName("java.lang.String"); ^ New.java:7: error: reached end of file while parsing } ^ 4 errors HELP ME>......

3 Answers  


What is odbc. how is it related to sql cli?

0 Answers  


What is represented by the connection object?

0 Answers  


HI ALL, How to Overcome "OutOfMemoryException"? when I am compiling source having more than 1000 LOC throwing this exception. Can any one give correct answer to my question? thx

5 Answers  


How do you know which driver is connected to a database?

3 Answers  


How to find number of records in result set?

2 Answers  


What is JDBC Connection? Explain steps to get Database connection in a simple java program.

0 Answers  


Categories