Standard and enforce the same through code reviews. This document delves into some fundamental Java programming techniques and provides a rich collection of coding practices to be followed by JAVA/J2EE based application development teams The best practices are primarily targeted towards improvement in the readability and maintainability of. When creating complex Java enterprise applications, do you spend a lot of time thumbing through a myriad of books and other resources searching for what you hope will be the API that's right for the project at hand?Java Database Best Practices rescues you from having to wade through books on each of the various APIs.
Where’s the cart? Now you can get everything with. To purchase books, visit Amazon or your favorite retailer.Questions? Or contact customer service:1-800-889-8969 / 707-827-7019When creating complex Java enterprise applications, do you spend a lot of time thumbing through a myriad of books and other resources searching for what you hope will be the API that's right for the project at hand?Java Database Best Practices rescues you from having to wade through books on each of the various APIs before figuring out which method to use! This comprehensive guide introduces each of the dominant APIs (Enterprise JavaBeans, Java Data Objects, the Java Database Connectivity API (JDBC) as well as other, lesser-known options), explores the methodology and design components that use those APIs, and then offers practices most appropriate for different types and makes of databases, as well as different types of applications.Java Database Practices also examines database design, from table and database architecture to normalization, and offers a number of best practices for handling these tasks as well. Learn how to move through the various forms of normalization, understand when to denormalize, and even get detailed instructions on optimizing your SQL queries to make the best use of your database structure.
Through it all, this book focuses on practical application of these techniques, giving you information that can immediately be applied to your own enterprise projects.Enterprise applications in today's world are about data- whether it be information about a product to buy, a user's credit card information, or the color that a customer prefers for their auto purchases. And just as data has grown in importance, the task of accessing that data has grown in complexity. Until now, you have been left on your own to determine which model best suits your application, and how best to use your chosen API. Java Database Practices is the one stop reference book to help you determine what's appropriate for your specific project at hand. Whether it's choosing between an alphabet soup of APIs and technologies-EJB, JDO, JDBC, SQL, RDBMS, OODBMS, and more on the horizon, this book is an indispensable resource you can't do without.Table of Contents.
Sun Microsystems created JDBC in the 90s to be the standard for data access on the Java Platform. JDBC has evolved since that time from a thin API on top of an ODBC driver to a fully featured data access standard whose capabilities have now surpassed its aging brother, ODBC. In recent applications, JDBC connects persistence layers (such as Hibernate or JPA) to relational data sources; but the JDBC API with its accompanying drivers are always the final piece connecting Java apps to their data! For more in depth (and entertaining) history, watch this movie on the history of Java and JDBC.
TYPE 1: The JDBC-ODBC BridgeThe JDBC-ODBC Bridge was the architecture that the first JDBC drivers adopted. This architecture requires an implementation of the JDBC API that then translates the incoming JDBC calls to the appropriate ODBC calls using the JNI (Java Native Interface). The requests are then sent to the underlying ODBC driver (which at the time was just a shell over the database native client libraries).
The bridge implementation shipped with the JDK so you only needed the ODBC drivers and native DB client libraries to get started. Although this was a klunky and headache prone approach, it worked.TYPE 2: Client BasedThe next generation of JDBC Drivers was the ever popular Type 2 driver architecture. This architecture eliminated the need for the ODBC driver and instead directly called the native client libraries shipped by the database vendors. This was quickly adopted by the DB vendors as it was quick and inexpensive to implement since they could reuse the existing C/C based native libraries. This choice still left Java developers worrying about version and platform compatibility issues (i.e.
Client version 6 is not supported on HP-Itanium processors). Some vendors still do their new development in their native clients first. So, don’t assume that if their website states that the JDBC driver supports Kerberos that they mean their Type 4 driver – they may mean Type 2!TYPE 3: Two Tier ArchitectureType 3 drivers sought to be a 100% Java solution but never really gained much traction.
Type 3 drivers had a Java client component and a Java server component, where the latter actually talked to the database. Although this was technically a full Java solution, the database vendors did not like this approach as it was costly – they would have to rewrite their native client libraries which were all C/C. In addition, this didn’t increase the architectural efficiency as we are really still a 3 tier architecture so it is easy to see why this was never a popular choice.TYPE 4: Wire Protocol DriversThe most popular JDBC driver architecture to date is Type 4.
This architecture encapsulates the entirety of the JDBC API implementation along with all the logic for communicating directly with the database in a single driver. This allows for easy deployment and streamlines the development process by having a single tier and a small driver all in a 100% java package. Type 4 drivers have been the traditional favorite of Java application developers since its inception due to the clean design and ease of use; drop in the driver jar and you’re up and running!TYPE 5: New!While not yet officially sanctioned by the JDBC Expert Group, there is quite a bit of discussion surrounding the new Type 5 driver proposal in the JDBC community. Getting down to the real functional differences, we see this list as the requirements for Type 5 Drivers as follows: Codeless ConfigurationThe ability to modify options, check statistics and interact with the driver while it is running. Typically through a standard JMX MBean.Performance ArchitectureDrivers specifically designed for multi-core, 64 bit, and virtualized environments.Clean Spec ImplementationStrict adherence to the JDBC standard, solving problems within the specification instead of using proprietary methods that promote vendor lock-in.Advanced FunctionalityType 5 drivers unlock code that has been trapped in the vendor native client libraries and bring that into the Java community. Features include but are not limited to: Bulk Load, Client side High Availability, Kerberos, and others. Pooling objects results in significant performance savings.
In JDBC, pooling Connection and Statement objects is the difference between a streamlined app and one that will consume all your memory. Make use of these pooling suggestions for all your JDBC applications!Connection Pooling – Enabling Connection pooling allows the pool manager to keep connections in a ‘pool’ after they are closed. The next time a connection is needed, if the connection options requested match one in the pool then that connection is returned instead of incurring the overhead of establishing another actual socket connection to the serverStatement Pooling – Setting the MaxPooledStatements connection option enables statement pooling. Enabling statement pooling allows the driver to re-use PreparedStatement objects.
When PreparedStatements are closed they are returned to the pool instead of being freed and the next PreparedStatement with the same SQL statement is retrieved from the pool rather than being instantiated and prepared against the server. Don’t use PreparedStatements by default!
If your SQL statement doesn’t contain parameters use the Statement object instead – this avoids a call to internal and wire level prepare methods and increases performance!MetaData Performance. Specify as many ar guments to DatabaseMetaData methods as possible. This avoids unnecessary scans on the database. For example, don’t call getTables like this:ResultSet rs = dbmd.getTables(null,null,null,null);Specifying at least the schema will avoid returning information on all tables for every schema when the request is sent to the server:ResultSet rs = dbmd.getTables(null,”test”,null,null);.
Most JDBC drivers populate the ResultSetMetaData object at fetch time because the needed data is returned in the server responses to the fetch request. Some underutilized pieces of ResultSetMetaData include:ResultSetMetaData.getColumnCountResultSetMetaData.getColumnNameResultSetMetaData.getColumnTypeResultSetMetaData.getColumnTypeNameResultSetMetaData.getColumnDisplaySizeResultSetMetaData.getPrecisionResultSetMetaData.getScale. Instead of using getColumns to get data about a table, consider issuing a dummy query and using the returned ResultSetMetaData which avoids querying the system tables!Commit ModeWhen writing a JDBC application, make sure you consider how often you are committing transactions. Every commit causes the driver to send packet requests over the socket. Additionally, the database performs the actual commit which usually entails disk I/O on the server.
Consider removing autocommit mode for your application and using manual commit instead to better control commit logic:Connection.setAutoCommit(false). Virtualization and Scalability are key factors to consider when choosing a JDBC driver. During the Performance Testing phase of your development cycle, ensure that your JDBC driver is using the least amount of CPU and Memory possible.
Java Database Best Practices Pdf Download For Windows 7
You can get memory and CPU performance numbers from your driver vendor to see how the drivers will scale when deployed in a Cloud or other virtualized environment.Network Traffic ReductionReduce network traffic by following these guidelines. TechniqueBenefitUse addBatch instead of using PreparedStatements to insert.Sends multiple insert requests in a single network packetEliminate unused column data from your SQL statementsRemoving long data and LOBs from your queries can save megabytes of wire transfer!Ensure that your database is set to the maximum packet size and that the driver matches that packet sizeFor fetching larger result sets, this reduces the number of total packets sent/received between the driver and server. Below is a list of common JDBC types and their default mapping to Java types. For a complete list of data types, conversion rules, and mapping tables, see the JDBC conversion tables in the JDBC Specification or the Java SE API documentation. JDBC TypesJava TypeCHAR, VARCHAR,LONGVARCHARjava.lang.StringCLOBjava.sql.ClobNUMERIC, DECIMALjava.math.BigDecimalBIT, BOOLEANBooleanBINARY, VARBINARY,LONGVARBINARYbyteBLOBjava.sql.BlobDATEjava.sql.DateTIMEjava.sql.TimeTIMESTAMPjava.sql.TimestampTINYINTbyteSMALLINTshortINTEGERintBIGINTlongREALfloatFLOAT, DOUBLEdouble. These advanced features are complex and meant as an overview. For all the bells and whistles for these advanced options, check your JDBC driver documentation!Debugging and LoggingWell-written JDBC drivers offer ways to log the JDBC calls going through the driver for debugging purposes.
As an example, to enable logging with some JDBC drivers, you simply set a connection option to turn on this spying capability:Class.forName(“com.ddtek.jdbc.sqlserver.SQLServerDriver”);Connection conn = DriverManager.getConnection(“jdbc:datadirect:sqlserver://Server1:1433;User=TEST;Password=secret;SpyAttributes=(log=(file)C:tempspy.log;linelimit=80;logTName=yes;timestamp=yes)”);Codeless Configuration (Hibernate and JPA)Codeless Configuration is the ability to change driver behavior without having to change application code. Using a driver under something like Hibernate or JPA means that the user cannot use proprietary extensions to the JDBC objects and should instead control and change driver behavior through connection options.Additionally, codeless configuration is the ability to monitor and change JDBC driver behavior while the driver is in use. For example, using a tool like JConsole to connect to a driver exported MBean and check the PreparedStatement pool stats as well as importing/exporting new statements on the fly to fine tune application performance.
Encrypt Your Data Using SSLEnsure that your data is secure by encrypting the wire traffic between the server and client using SSL encryption:. Set the EncryptionMethod connect option to SSL. Specify the location and password of the trustStore file used for SSL server authentication. Set connect options or system properties (javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword). If your database server is configured for SSL client authentication, configure your keyStore information:. Specify the location and password of the keyStore file.
Database Books Pdf Free Download
Either set connect options or Java system properties (javax.net.ssl.keyStore and javax.net.ssl.keyStorePassword). If any key entry in the keyStore file is passwordprotected,set the KeyPassword property to thekey password.Single Sign-on With KerberosKerberos is an authentication protocol, which enables secure proof of identity over a non-secure network. It is also used for enabling single sign-on across multiple sites by delegating credentials. To enable Kerberos:. Set the authenticationMethod connect option to Kerberos.
Modify the krb5.conf file to contain your Kerberos realm and the KDC name for that realm. Alternatively, you can set the java.security.krb5.realm and java.security.krb5.kdc system properties. If using Kerberos authentication with a Security Manager,grant security permissions to the application and driver. These security features are not supported by all databases and database versions. Check to ensure your database is setup appropriately before attempting Kerberos and SSL connections.Application FailoverApplication failover is the ability for a driver to detect a connection failure and seamlessly reconnect you to an alternate server.