ÿþ<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=unicode"> <META content="MSHTML 6.00.2900.2180" name=GENERATOR> <style type="text/css"> .style1 { font-size: medium; } </style> </HEAD> <BODY> <P> <TABLE style="WIDTH: 734px; HEIGHT: 161px" cellSpacing=1 cellPadding=1 width=734 align=center bgColor=aquamarine border=1> <TR> <TD><STRONG>CS4347.501 Database Systems</STRONG> </TD> <TD>Monday/Wednesday 7:00 to 8:15</TD></TR> <TR> <TD>Instructor: John Cole</TD> <TD>Room ECS&nbsp;2.415</TD></TR> <TR> <TD> Teaching Assistant: <a href="mailto:ziying.tang@utdallas.edu;">Ziying Tang</a> Office hours: MW 4:45 to 6:45 in 4.416.</TD> <TD>Last update: 2/6/2011</TD></TR> <TR> <TD><A href="CS4347SyllabusSpring2011.doc" >Syllabus</A></TD> <TD><A href="CS4347SchedSpring2011A.htm">Schedule (Subject to change)</A></TD></TR> <TR> <TD colSpan=2>Book: <EM>Fundamentals of Database Systems, </EM>Sixth edition, by Elmasri and Navathe.&nbsp; The fifth edition is organized differently enough that you would have a hard time following the schedule.</TD></TR></TABLE></P> <P> <TABLE style="WIDTH: 514px; HEIGHT: 103px" cellSpacing=1 cellPadding=1 width=514 align=center border=1> <TR> <TD> <P> This is the undergraduate version of Database Design.</P></TD></TR> <TR> <TD> <h3 style="width: 566px">Our TA, Ziying Tang, will be available to grade projects during her office hours Monday and Wednesday, May 2 and May 4, from 4:00 to 6:00.&nbsp; She is in 4.415/416.&nbsp; She is also in her lab every afternoon, and says you can drop by any time.&nbsp; Best to e-mail to set up an appointment, though. </h3> <h3 style="width: 566px">Exam 2 is TODAY, May 2, 2011 at 7:00 PM in our usual classroom.&nbsp; There will be no other exams.&nbsp; I will keep office hours on Wednesday, May 4, from about 4:00 to 6:00 in 4.611.</h3> <p style="width: 566px">Also, a few of you have asked about grading, since the syllabus weighs &quot;Quizzes and homework&quot; as 15%.&nbsp; However, we have only had one homework assignment and no quizzes, largely because of trying to catch up after missing two classes.&nbsp; Therefore, the homework will be weighted at 5% and the other 10% distributed among the two exams.</p> <p style="width: 566px">Thanks for a great semester.&nbsp;</p> </TD></TR> <TR> <TD> <P><a href="company.zip">Company database from the textbook</a></P> <P><a href="./Database6e/121071-0136077366_ppt1.zip">Slides for Chapters 1-5</a><br> <a href="./Database6e/0136077366_ppt2-121741.zip">Slides for Chapters 6-10</a><br> <a href="./Database6e/0136077366_ppt3-121742.zip">Slides for Chapters 11-15</a> <br><a href="./Database6e/0136077366_ppt4-122499.zip">Slides for Chapters 16-20</a></P> </TD></TR> <TR> <TD> <span class="style1">Midterm grades have been posted.&nbsp; Due to not having exam grades (the TA didn&#39;t record them) this is based only upon the first two homework assignments, and may not be an accurate reflection of your standing.&nbsp; The TA will be in contact with you, so bring your exam to class on</span><span class="style1"><strong> Monday, March 21.&nbsp; </strong>Homework grades with comments will be posted by midnight, Monday, March 14.</span></TD></TR> <TR> <TD> <h3>Some general notes on Phase 1 (All of these things were discussed in class):</h3> <ul> <li>Many of you didn't seem to remember that you needed meter readings. </li> <li>Addresses are not a single field. At the very least they should be broken out into multiple lines, although Zip code should always be a separate field for mail sorting purposes.</li> <li>Water is billed by the gallon while many other services are billed on a per-month basis or as a one-time charge.&nbsp; Your tables should take this into account.</li> <li>Many of you hard-coded all possible services into the bill itself, meaning that if the city decides to add a new service, such as perhaps alarm system monitoring, your entire structure would have to change.</li> <li>Payments should be a separate table.&nbsp; Done right, you should be able to write a single query that determines the balance due.&nbsp; People do overpay, underpay, or just plain forget to pay their water bills.</li> <li>Many of you forgot about taxes.</li> </ul> </TD></TR></TABLE> <P><STRONG> Homework Assignments:<br><br> <a href="DatabaseHW1.htm">Homework Assignment Due February 11, 2011</a> (Per eLearning) <br><a href="CS4347Spring2011Asg1.htm">Project Phase 1 Due March 2, 2011</a> (changed to March 4) <br><a href="CS4347Spring2011Asg2.htm">Project Phase 2 Due April 4, 2011</a><br><a href="CS4347Spring2011Asg4.htm">Project Phase 3, Due April 27, 2011</a></STRONG></P> <P><STRONG> <BR></P></STRONG> <TABLE style="WIDTH: 800px; HEIGHT: 138px" cellSpacing=1 cellPadding=1 width=800 border=1> <TR> <TD colSpan=2> <P>In-Class Notes.&nbsp; These are what I wrote using WordPad during class, if any. </P></TD></TR> <TR> <TD style="width: 250px"></TD> <TD style="width: 550px"> <a href="../../../../*%20*%20To%20change%20this%20template,%20choose%20Tools%20|%20Templates%20*%20and%20open%20the%20template%20in%20the%20editor.%20*/package%20dbconnect;import%20java.*;/**%20*%20*%20@author%20John%20*/public%20class%20DBConnectMain%20{%20%20%20%20%20private%20java.sql.Connection%20%20con%20=%20null;%20%20%20%20%20private%20final%20String%20url%20=%20%22jdbc:sqlserver:/%22;%20%20%20%20%20private%20final%20String%20serverName=%20%22localhost%22;/%20%20%20%20%20private%20final%20String%20portNumber%20=%20%2213579%22;%20%20%20%20%20private%20final%20String%20portNumber%20=%20%221433%22;%20%20%20%20%20private%20final%20String%20databaseName=%20%22Company%22;%20%20%20%20%20private%20final%20String%20userName%20=%20%22sa%22;%20%20%20%20%20private%20final%20String%20password%20=%20%22SECRET%22;%20%20%20%20%20/%20Informs%20the%20driver%20to%20use%20server%20a%20side-cursor,%20%20%20%20%20/%20which%20permits%20more%20than%20one%20active%20statement%20%20%20%20%20/%20on%20a%20connection.%20%20%20%20%20private%20final%20String%20selectMethod%20=%20%22cursor%22;%20%20%20%20%20/%20Constructor%20%20%20%20%20public%20DBConnectMain(){}%20%20%20%20%20private%20String%20getConnectionUrl(){%20%20%20%20%20%20%20%20%20%20return%20%22jdbc:sqlserver:/localhost:1433;instanceName=Infopoint103;databaseName=Company;%22;%20%20%20%20%20}%20%20%20%20%20private%20java.sql.Connection%20getConnection(){%20%20%20%20%20%20%20%20%20%20try{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Class.forName(%22com.microsoft.sqlserver.jdbc.SQLServerDriver%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(getConnectionUrl());%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20con%20=%20java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if(con!=null)%20System.out.println(%22Connection%20Successful!%22);%20%20%20%20%20%20%20%20%20%20}catch(Exception%20e){%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e.printStackTrace();%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22Error%20Trace%20in%20getConnection()%20:%20%22%20+%20e.getMessage());%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20return%20con;%20%20%20%20%20%20}%20%20%20%20%20/*%20%20%20%20%20%20%20%20%20%20Display%20the%20driver%20properties,%20database%20details%20%20%20%20%20*/%20%20%20%20%20public%20void%20displayDbProperties(){%20%20%20%20%20%20%20%20%20%20java.sql.DatabaseMetaData%20dm%20=%20null;%20%20%20%20%20%20%20%20%20%20java.sql.ResultSet%20rs%20=%20null;%20%20%20%20%20%20%20%20%20%20try{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20con=%20this.getConnection();%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if(con!=null){%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dm%20=%20con.getMetaData();%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22Driver%20Information%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22/tDriver%20Name:%20%22+%20dm.getDriverName());%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22/tDriver%20Version:%20%22+%20dm.getDriverVersion%20());%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22/nDatabase%20Information%20%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22/tDatabase%20Name:%20%22+%20dm.getDatabaseProductName());%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22/tDatabase%20Version:%20%22+%20dm.getDatabaseProductVersion());%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22Avalilable%20Catalogs%20%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rs%20=%20dm.getCatalogs();%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20while(rs.next()){%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22/tcatalog:%20%22+%20rs.getString(1));%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rs.close();%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rs%20=%20null;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20closeConnection();%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}else%20System.out.println(%22Error:%20No%20active%20Connection%22);%20%20%20%20%20%20%20%20%20%20}catch(Exception%20e){%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e.printStackTrace();%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20dm=null;%20%20%20%20%20}%20%20%20%20%20private%20void%20closeConnection(){%20%20%20%20%20%20%20%20%20%20try{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if(con!=null)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20con.close();%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20con=null;%20%20%20%20%20%20%20%20%20%20}catch(Exception%20e){%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e.printStackTrace();%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20}%20%20%20%20%20public%20static%20void%20main(String[]%20args)%20throws%20Exception%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20DBConnectMain%20myDbTest%20=%20new%20DBConnectMain();%20%20%20%20%20%20%20%20%20%20myDbTest.displayDbProperties();%20%20%20%20%20%20%20}}"> /*<br>* Sample JDBC program courtesy of Evan Williams<br>*/<br><br>package dbconnect;<br>import java.*;<br><br>/**<br>*<br>* @author John<br>*/<br> public class DBConnectMain {<br><br>private java.sql.Connection con = null;<br> private final String url = &quot;jdbc:sqlserver://&quot;;<br>private final String serverName= &quot;localhost&quot;;<br>// private final String portNumber = &quot;13579&quot;;<br> private final String portNumber = &quot;1433&quot;;<br>private final String databaseName= &quot;Company&quot;;<br>private final String userName = &quot;sa&quot;;<br>private final String password = &quot;SECRET&quot;;<br>// Informs the driver to use server a side-cursor,<br>// which permits more than one active statement<br>// on a connection.<br>private final String selectMethod = &quot;cursor&quot;;<br><br>// Constructor<br>public DBConnectMain(){}<br><br>private String getConnectionUrl(){<br>return &quot;jdbc:sqlserver://localhost:1433;instanceName=Infopoint103;databaseName=Company;&quot;;<br> }<br><br>private java.sql.Connection getConnection(){<br>try{<br> Class.forName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;);<br> System.out.println(getConnectionUrl());<br>con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);<br> if(con!=null) System.out.println(&quot;Connection Successful!&quot;);<br> }catch(Exception e){<br>e.printStackTrace();<br>System.out.println(&quot;Error Trace in getConnection() : &quot; + e.getMessage());<br>}<br>return con;<br>}<br> <br>/*<br>Display the driver properties, database details<br>*/<br><br> public void displayDbProperties(){<br>java.sql.DatabaseMetaData dm = null;<br> java.sql.ResultSet rs = null;<br>try{<br>con= this.getConnection();<br> if(con!=null){<br>dm = con.getMetaData();<br>System.out.println(&quot;Driver Information&quot;);<br>System.out.println(&quot;\tDriver Name: &quot;+ dm.getDriverName());<br> System.out.println(&quot;\tDriver Version: &quot;+ dm.getDriverVersion ());<br> System.out.println(&quot;\nDatabase Information &quot;);<br>System.out.println(&quot;\tDatabase Name: &quot;+ dm.getDatabaseProductName());<br>System.out.println(&quot;\tDatabase Version: &quot;+ dm.getDatabaseProductVersion());<br>System.out.println(&quot;Avalilable Catalogs &quot;);<br>rs = dm.getCatalogs();<br>while(rs.next()){<br> System.out.println(&quot;\tcatalog: &quot;+ rs.getString(1));<br>}<br>rs.close();<br> rs = null;<br>closeConnection();<br>}else System.out.println(&quot;Error: No active Connection&quot;);<br>}catch(Exception e){<br>e.printStackTrace();<br>}<br> dm=null;<br>}<br><br>private void closeConnection(){<br>try{<br> if(con!=null)<br>con.close();<br>con=null;<br>}catch(Exception e){<br> e.printStackTrace();<br>}<br>}<br>public static void main(String[] args) throws Exception<br>{<br>DBConnectMain myDbTest = new DBConnectMain();<br> myDbTest.displayDbProperties();<br>}<br><br>}<br></a></TD></TR> <TR> <TD style="width: 250px">Code to read from the database</TD> <TD style="width: 497px"> These imports are requiired.<br>import java.sql.*;<br>import java.util.*;<br> <br>You&#39;ll need these variables, or something like them, for this to work:<br> private static Connection cnSQL;<br>private static String strSql;<br>private static Statement stmtSQL;<br><br>Finally, the code:<br>&nbsp;stmtSQL = cnSQL.createStatement();<br>ResultSet rs = stmtSQL.executeQuery(&quot;SELECT * FROM Employee&quot;);<br>while (rs.next())<br>{<br>strdata = rs.getString(&quot;fname&quot;) + &quot; &quot; + rs.getString(&quot;lname&quot;);<br>System.out.println(strdata);<br>} <a href="%20%20%20%20%20%20%20%20stmtSQL%20=%20cnSQL.createStatement();%20%20%20%20%20%20%20%20ResultSet%20rs%20=%20stmtSQL.executeQuery(%22SELECT%20*%20FROM%20Employee%22);%20%20%20%20%20%20%20%20while%20(rs.next())%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20%20%20strdata%20=%20rs.getString(%22fname%22)%20+%20%22%20%22%20+%20rs.getString(%22lname%22);%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(strdata);%20%20%20%20%20%20%20%20}%20"> <br></a></TD></TR></TABLE> </BODY></HTML>