JavaDeploy
SiteMap
JSP - Servlets
JDBC
EJB Concepts
Entity Beans
JDBC
«Prev
Intro JDBC
Learning JDBC
JDBC Course Project
JDBC Case Study
JDBC Team
Business Case Conclusion
Distributed Objects
Enterprise Solutions JDBC
System Organization Role
Relational Databases
JDBC/ODBC Relationship
Microsoft API ODBC
SQL Database Processing
JDBC Architectural Models
n-tier Architectural Benefits
JDBC Mechanics
Enterprise Conclusion
JDBC Connection
JDBC URL Connection
JDBC Driver
Driver Types
Driver Manager
Sample JDBC Program
JDBC DBMS Conclusion
Database Tables
Statement Objects
Examining Query Results
Accessing Data Methods
Database Metadata
Obtain Database Content
Prepared Statements
Interface ResultSet
Transaction Methods
Isolation Levels
JDBC Batch Updates - Exercise
Using batch updates and Prepared Statements
Objective:
Write code that prints information in a database.
Background/overview - Briefing Information
You have had an opportunity to learn about batch updates and
PreparedStatements
By now, you should have an understanding of options that are available to address some of the issues discussed at the start of this module. You know of a couple that may be of help when you need to add tables and when you may be concerned about performance. Specifically, you looked at the
PreparedStatement
interface and batch updates. You saw that each had a role in JDBC applications.
You saw that
PreparedStatements
are helpful if you have to execute the same statement again and again, with only the arguments varying from one invocation to the next. Batch updates are useful if the statements themselves vary in other ways (some may be
UPDATEs
, and others
INSERTS
, for example).
Now it is time to use what you have learned and incorporate it in ways that meet the Brazil Project database requirements.
Download Files
The file used is Example4.java of the JDBCCourse download set (brazilproject.zip) and is available in the
Resources
section accessible through your course toolbar.
Instructions
Edit the Example4.java program
Locate the <<MODIFICATION 1>> tag in the program. The program is currently written using the execute() method to direct SQL commands to the database. Change the program to use the addBatch() and executeBatch() methods. Directions about where these changes should occur are in the program comments.
Locate the <<MODIFICATION 2>> tag. Change the program so that it uses the appropriate method to create a PreparedStatement.
Locate the <<MODIFCATION 3>> tag. Change the program so that it uses the correct method names for the type of data which is set in the prepared statement. The data type used in the method must match the type of the method's second argument. Also, set the correct parameter indexes as the first argument of these methods.
Locate the <<MODIFICATION 4>> tag. Add methods to obtain the SQLState, ErrorCode, and Messages and print them out.
Compile the program.
Test the program by running it from the command line. (Don't forget to run the setJV102env.bat script first.)
To review the database changes, start Cloudscape's administrative tool, Cloudview. Cloudview will allow you to view the rows in a Cloudscape database. Run startCloudview.bat to start Cloudview. Once it is running, open the BrazilProjects database, and you should see the new DOCTORS table. If you open the table, you should be able to see the rows your program added.