1 / 8

Java database Programming

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.

palmer
Download Presentation

Java database Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 Oracle JDBC Driver JDBC-ODBC Bridge Driver Microsoft ODBC Driver Local or remote Mysql DB Local or remote Oracle DB MicroSoft Access Database

  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

More Related