Week 2 Unit 3: Creating a JDBC Application January, 2015
JDBC Overview Java Database Connectivity (JDBC) Java-based data access technology Defines how a client can connect, query, and update data in a database JDBC API JDBC connections support creation and execution of statements ResultSet presents the outcome after a statement has been executed 2
Why Use JDBC? Advantages of JDBC Clean and easy for small applications Good performance with large amounts of data Allows optimization of SQL requests Reuse of existing JDBC libraries (Liquibase, Hibernate) Disadvantages of JDBC Large programming overhead for large projects Concurrency support and transaction and connection management required Initial creation of database structures required 3
JDBC Sample Uses standard database access (JDBC) Needs only a Web container, so can run in both runtimes Java Web (1.x) Java EE 6 Web Profile (2.x) Java EE 6 Web Profile (2.x) or Java Web (1.x) PersistenceWithEJBServlet Person PersonDAO Web Container JDBC DB Schemas 4
JDBC Sample Import to Eclipse as Existing Projects into Workspace Location: <SDK_path>\samples\persistence-with-jdbc 5
JDBC Sample Building Blocks: Person.java holds the information for a person PersonDAO.java performs all operations with DB PersistenceWithJDBCServlet.java provides interaction with the end users and looks up the DataSource from JNDI web.xml web application descriptor; defines datasource resource 6
JDBC Sample Run the sample Run on Server Configure SAP HANA Cloud Server hanatrial.ondemand.com Request URL https://<application_name><account_name>. hanatrial.ondemand.com/persistence-withjdbc/ 7
JDBC Sample In the background: A new schema is created Schema is bound to the application When app requests data source the app gets connected to this schema Maximum 8 parallel database connections per schema When application is undeployed, the schema is not removed When application is redeployed, it uses same schema and bindings 8
How Can I See the SQL Statements Sent to the Database? SQL Trace Provides a log of selected SQL statements Relevant for both JPA and JDBC applications Integrated in the standard trace log files Disabled by default Scenarios Investigate database access-related performance issues Determine inefficient SQL statements 9
How to Enable the SQL Trace Set the log level of com.sap.core.persistence.sql.trace to DEBUG Tools: Eclipse IDE SAP HANA Cloud Platform Cockpit 10
How to Read SQL Trace Records The SQL trace is written in the default trace log file File name prefix ljs_trace_vsa Tools: Eclipse IDE SAP HANA Cloud Platform Cockpit 11
What You ve Learned in This Unit What JDBC is The advantages and disadvantages of JDBC What a persistence-enabled JDBC application looks like What happens in the background when an application is deployed and started How to trace the SQL statements performed by your application How to enable, disable, and display the SQL trace recordings 12
Contact information: open@sap.com
2014 SAP SE or an SAP affiliate company. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP SE s or its affiliated companies strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions. 14