What is JDBC?
By: Sun
The JDBC API is a Java API that can access any kind of tabular data, especially data stored in a Relational Database.
JDBC helps you to write java applications that manage these three programming activities:
- Connect to a data source, like a database
- Send queries and update statements to the database
- Retrieve and process the results received from the database in answer to
your query
The following simple code fragment gives a simple example of these three steps:
Connection con = DriverManager.getConnection ( "jdbc:myDriver:wombat", "myLogin","myPassword"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1"); while (rs.next()) { int x = rs.getInt("a"); String s = rs.getString("b"); float f = rs.getFloat("c"); }
This short code fragment instantiates aDriverManager
object to connect to a database driver and log into the database, instantiates aStatement
object that carries your SQL language query to the database; instantiates aResultSet
object that retrieves the results of your query, and executes a simplewhile
loop, which retrieves and displays those results. It's that simple.
Archived Comments
1. java calculator code
View Tutorial By: Ryan at 2016-03-11 11:19:46
2. how to connect jdbc in java on mysql
View Tutorial By: saravana kumar at 2012-01-30 06:06:57
3. how to connect jdbc in java on mysql
View Tutorial By: naseem at 2011-10-26 19:26:45
4. pls send me the brief description about jdbc connectivity to mysql
View Tutorial By: vikas at 2011-08-09 07:07:53
5. Very precise and informative tutorial. Appreciated very much!
View Tutorial By: Rishi Raj at 2011-07-08 12:25:04
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
TEXT datatype SPLIT in MSSQL - to solve the 8000 limit set by varchar
What is Referential Integrity in databases?
Handling CSV in Stored Procedures
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError
Calling a Stored Procedure from JDBC in Java
setSavepoint and releaseSavepoint Example in Java
PreparedStatement Example in Java
Creating Database Tables Using ANT
Using the DriverManager Class vs Using a DataSource Object for a connection
Stored Procedures example in SQL