\begin{frame}[fragile]
\frametitle{Dynamic SQL: JDBC}
A Java Database Connectivity (JDBC) example:
\begin{exampleblock}{}\vspace{-1ex}
{\scriptsize
% \ttfamily\lipsum
% \fontseries{lc}\selectfont
% \lipsum
% import java.sql.* ;
%
% public class ShowStudents {
% public static void main(String args[]) throws Exception {
% String url = "jdbc:mysql://localhost/db" ;
% System.setProperty("jdbc.drivers",
% "org.gjt.mm.mysql.Driver");
\begin{lstlisting}[language=Java]
Connection conn = DriverManager.getConnection(url);
Statement stat = conn.createStatement() ;
ResultSet rs = stat.executeQuery(
"select sid, name from students"
);
while (rs.next()) {
int sid = rs.getInt("sid");
String name = rs.getString("name");
System.out.println(sid + ": " + name);
}
conn.close();
\end{lstlisting}\vspace{-4ex}
\begin{tikzpicture}[overlay,nodes={rectangle,fill=red!20,rounded corners=1mm},inner sep=.5mm]
\node [shift={(-3.7cm,1.4cm)},align=left] at (current page.south east) {getInt(...), getString(...)\\
fetch column values by name};
\end{tikzpicture}
\begin{tikzpicture}[overlay,nodes={rectangle,fill=red!20,rounded corners=1mm},inner sep=.5mm]
\node [shift={(-.22cm,1.75cm)},align=left] at (current page.south west) {fetch results\\
row by row};
\end{tikzpicture}
}
\end{exampleblock}
Use \sql{rs.wasNull(attribute)} to check if \sql{attribute} is \sql{null}.
\pause\smallskipp
\begin{goal}{}
The \emph{Impedance Mismatch}: database query language does not match the application programming language.
\end{goal}
(Different data models and data types.)
% Note that:
% \begin{itemize}
% \item SQL data types are mapped to Java data types
% \item \sql{rs.wasNull(attribute)} checks if the attribute is \sql{null}
% \end{itemize}
\end{frame}