Database Reporting
Database Reporting
2. Driver Manager
3. Connection
4. Statement
5. Result Set
JDBC Drivers
• Driver handles the communication between database and the
application.
2. Create
3. Create
Lesson 6/ Example 6
Prepared Statements
• Lets look at the order of the regular query execution.
– Class.forName("com.mysql.cj.jdbc.Driver");
– Connection conn = DriverManager.getConnection(dbURL, dbUser,
dbPass);
– conn.close();
Prepared Statements (cont.)
• This mechanism is not efficient if the query needs to be run
repeately with different parameters.
– preStat.set<DataType>(<index>,<variable/value>);
– preStat.executeUpdate();
– conn.close();
Prepared Statement Example
String pQuery = “insert into vegetables
(Name,Price,Quantity) values(?,?,?);
JasperViewer.viewReport(jp);
conn.close();
} catch (SQLException| ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
Lesson 6/Example 5
Take home assignment
• Watch this YouTube tutorial on setting up Jasper Studio and
Jasper Reports.
– Create and Print Reports in Netbeans 16 using JasperReport with MySQL
Server Database - Java Maven
– https://www.youtube.com/watch?v=NlPpeLVbysA