Accessing Databases with JDBC Introduction Introdution A database
Accessing Databases with JDBC Introduction
Introdution • A database is an organized collection of data. There are many different strategies for organizing data to facilitate easy access and manipulation. A database management system (DBMS) provides mechanisms for storing, organizing, retrieving and modifying data for many users. Database management systems allow for the access and storage of data with- out concern for the internal representation of data.
Today’s most popular database systems are relational databases Some popular relational database management systems (RDBMSs) are Microsoft SQL Server, Oracle, Sybase, IBM DB 2, Informix, Postgre. SQL and My. SQL. The JDK now comes with a pure-Java RDBMS called Java DB Java programs communicate with databases and manipulate their data using the Java Database Connectivity (JDBC™) API. A JDBC driver enables Java applications to connect to a database in a particular DBMS and allows you to manipulate that database using the JDBC API.
Overview SQL
Program // Data Retrieving From Access Data. Base import java. sql. *; class DBAccess { Connection con; Statement st; Result. Set rs; public static void main(String[] args) { try { Class. for. Name("sun. jdbc. odbc. Jdbc. Odbc. Driver"); con=Driver. Manager. get. Connection("jdbc: odbc: connection 1124"); st=con. create. Statement(); rs=st. execute. Query("SELECT * FROM Student");
Continue Program while(rs. next()) {System. out. print("Student_Id: "); System. out. println(rs. get. Int(1)+"t "); System. out. print("Student_Name: "); System. out. println(rs. get. String(2)+"t "); /*System. out. print("Student_Marks in Java: "); System. out. println(rs. get. Int(3)+"t "); System. out. print("Student_Marks in Electronic : "); System. out. println(rs. get. Int(4)+"t "); */ } //while rs. close(); st. close(); con. close(); } //try
Continue Program catch(Class. Not. Found. Exception e) { e. print. Stack. Trace(); }// catch(SQLException ee) { ee. print. Stack. Trace(); }// catch }//main() } //class
- Slides: 7