Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.

Similar presentations


Presentation on theme: "Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity."— Presentation transcript:

1 Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity Provides Java programmers with a uniform interface for accessing and manipulating a wide range of relational databases

2 Java Program JDBC API mySQL JDBC Driver JDBC-ODBC Bridge Driver Oracle JDBC Driver Local or remote Mysql DB MicroSoft Access Database Local or remote Oracle DB Microsoft ODBC Driver

3 Developing Database Application Using JDBC JDBC API is a Java Program interface to generic SQL database that enables Java developers to develop DBMS-independent Java application using a uniform interface JDBC API consists of classes and interfaces for establishing connections with database, sending SQL statements to databases, processing the results of the SQL statements Four key interfaces: Driver, Connection, Statement, and ResultSet

4 Loading drivers Class.forName(“JDBCDriverClass”); Access: sun.jdbc.odbc.JdbcOdbcDriver Mysql: com.mysql.jdbc.Driver Oracle: oracle.jdbc.Driver.OracleDriver Establishing connection Connect conn = DriverManager.getConnection(databseURL); Access:jdbc:odbc:dataSource Mysql: jdbc:mysql://hostname/dbname Oracle:jdbc:oracle:thin:@hostname:port#:oracleDSSID

5 Creating statements Statement st = conn.createStatement(); Executing statement St.executeUpdate(String sql) St.executeQuery(String sql) return result in ResultSet ResultSet rs = st.executeQuery(“select firstName from Student where lastName =‘Smith’ “);

6 Processing ResultSet. The resultSet maintains a table whose current row can be retrieved. Res.next() move to the next row Various methods to retrieve values Res.getString(1) Res.getString(“firstName”)

7 Servlet and JSP (java Server Page) Are Java program that run on a web server Can be used to process client request or produce dynamic web pages. public class SomeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Use "request" to read incoming HTTP headers (e.g. cookies) // and HTML form data (e.g. data the user entered and submitted) // Use "response" to specify the HTTP response line and headers // (e.g. specifying the content type, setting cookies). PrintWriter out = response.getWriter(); // Use "out" to send content to browser } }

8 Multimedia Playing audio With Java 2, you can play sound files in the.wav,.aiff,.midi,.au and.rmf format Running audio on a separate thread Displaying images


Download ppt "Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity."

Similar presentations


Ads by Google