Transcript Applet class - City University of New York
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
mySQL JDBC Driver Java Program JDBC API Oracle JDBC Driver Local or remote Mysql DB Local or remote Oracle DB JDBC-ODBC Bridge Driver Microsoft ODBC Driver MicroSoft Access Database
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
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
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’ “);
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”)
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
} }
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