JDBC (Java Database Connectivity) - Import the jdbc classes using import statements - load the jdbc driver - Connect to the database (getConnection()) - Submit queries, inserts, updates and process responses (often via a statement) * Updates are used to add to, modify, or remove from a table in the database * Queries are used to look things up in the database - Must commit (make permanent) any changes. This can be circumvented by using auto-commit. Disconnect from the database - Accessing the database 1. Connect - Get a Connection (built-in to Java) 2. Create a statement - can be one of the three types. - The createStatement() method 'attaches' the statement to the connection. 3 Execute updates and/or queries. A query to a database returns the records in a ResultSet. - ResultSet data is accessed one record at a time. * next() advances throught the set and also informs when exhausted. * Must use the get methods in the class with congruent type. - Prepared Statement * Has parameters for issuing the same SELECT with a small number of variations each time. * Setting the parameters is done by number, starting at 1. - SQL DROP is used to remove a table from the db. Servlet Intro (Brief) - Test Basic Servlet by direct access: https://.kutztown.edu:8443/Snoop/SnoopServlet - Apache Tomcat is a Java enabled server. It can host servlets. * It sniffs your webapps directory. > That directory belongs to Tomcat. DO NOT WORK IN THE webapps DIRECTORY!!! - To avoid ruining everyone's night, when working on servlets: * Infinite loops MUST be avoided. * The servlet receives the request, fulfills it (often in a thread) and goes back to wait mode (for the next request) - To remove a servlet, delete its war file. To update it, replace its war file. - We like working with HTTPServlet * It is the easiest and most straightforward. * The request (HTTPServletRequest) and response (ibid) require little overhead to obtain lots of info. - web.xml contains the servlet info * The URL used to access the servlet class is often an alias that gets resolved in web.xml including the redirect from the (possibly different) URL to the servlet class * in must match in * The slash in the tag represents the classes directory under WEB-INF - Packages in servlets start at the classes directory, which is in the Tomcat classpath. * Most frameworks require servlet Java code to be in a package, i.e. the class isn't in classes dir