jdbc tutorial_JDBC tutorial

jdbc tutorial

Welcome to JDBC tutorial. Java DataBase Connectivity (JDBC) is one of the most widely used API in enterprise applications. This is because most of the applications use some sort of database connectivity. I have recently posted a lot of JDBC tutorials related to basic JDBC, DataSource and it’s integration with Spring Framework.

Welcome to the JDBC tutorial. Java Database Connectivity (JDBC) is one of the most widely used APIs in enterprise applications. This is because most applications use some kind of database connection. I've recently published many JDBC tutorials related to basic JDBC, DataSource and its integration with Spring Framework.

JDBC Tutorial ( JDBC Tutorial )

JDBC Tutorial

This is a index post for all the jdbc tutorials I had posted earlier. If you are new to JDBC then you should go through these JDBC tutorials in order for better understanding.


This is an index release of all the jdbc tutorials I've posted before. If you are new to JDBC, you should read these JDBC tutorials for a better understanding.

  1. JDBC Example

    JDBC API helps us in writing loosely coupled code from database drivers. This article explains about different types of database drivers we have and which one is the most commonly used and why. This is a good post to start with to learn about Database Connection, Statements and ResultSet. How they all work together to perform specific database operations.

    This article also shows you how to write JDBC programs in order to keep them loosely coupled from Database drivers, that helps in switching from one database server to another easily with just configuration changes.

    JDBC example

    JDBC API helps us write loosely coupled code from database drivers. This article describes the different types of database drivers we have, along with the most commonly used ones and why. This is a good article to start learning about database connections, statements and result sets. How they work together to perform a specific database operation.

    This article also showed you how to write JDBC programs so that they remain loosely coupled with the database driver, which helps you easily switch from one database server to another with a configuration change.

  2. JDBC Statement vs PreparedStatement

    JDBC API provides two ways to communicate with database – Statement and PreparedStatement. Statement is easy to use but it can lead to SQL injection, that is very common way of hacking any application. This article clearly shows how SQL injection can be performed with SQL Statements and why we should use PreparedStatement to avoid SQL injection attacks.

    This article goes further in explaining some of the major benefits we get from using PreparedStatement over Statement such as caching, object oriented programming and elegant looking code.

    JDBC语句与PreparedStatement

    JDBC API提供了两种与数据库通信的方式StatementPreparedStatement 。 语句易于使用,但是会导致SQL注入,这是入侵任何应用程序的非常常见的方式。 本文清楚地说明了如何使用SQL语句执行SQL注入以及为什么我们应该使用PreparedStatement来避免SQL注入攻击。

    本文将进一步说明通过使用PreparedStatement而不是Statement所获得的一些主要好处,例如缓存,面向对象的编程和美观的代码。

  3. JDBC PreparedStatement IN Clause Alternatives

    Since JDBC PreparedStatement is pre-compiled, we can’t use it with IN clause. Rather than going back to Statement, there are some alternative approaches that we can use to get over this shortcomings of Prepared Statement. This article provides four different alternative approaches that we can take to support IN clause with prepared statements. You should read it because you never know when you are going to need it, also it’s one of the most asked interview question related to JDBC.

    JDBC PreparedStatement IN子句替代

    由于JDBC PreparedStatement是预编译的,因此我们不能将其与IN子句一起使用。 除了返回到Statement之外,我们还可以使用一些替代方法来克服Prepared Statement的这一缺点。 本文提供了四种不同的替代方法,我们可以采用这些替代方法来通过准备好的语句来支持IN子句。 您应该阅读它,因为您永远不知道何时需要它,它也是与JDBC相关的面试最常见的问题之一。

  4. JDBC Batch Processing

    If you are working with bulk data and have to execute a lot of queries, it’s not good idea to do it one by one. JDBC provides batch processing support that will be much more faster than processing single query at a time. This article shows you how to write programs for batch processing.

    It goes further into discussing what to do if there is an exception thrown by one of the queries in the batch.

    JDBC批处理

    如果您要处理大量数据并且必须执行很多查询,那么一个接一个地做不是一个好主意。 JDBC提供了批处理支持,这比一次处理单个查询要快得多。 本文介绍如何编写用于批处理的程序。

    它进一步讨论了如果批处理中的一个查询引发异常,该怎么办。

  5. JDBC CallableStatement Example

    We can use JDBC API CallableStatement to execute stored procedures. Oracle Database provides Cursors and DB Objects that we can use in stored procedures IN/OUT parameters. This tutorial provides specific details of these with example programs.

    JDBC CallableStatement示例

    我们可以使用JDBC API CallableStatement执行存储过程。 Oracle数据库提供了可在存储过程IN / OUT参数中使用的游标和数据库对象。 本教程通过示例程序提供了这些内容的具体细节。

  6. JDBC DataSource Example

    Most of the times we are looking for more than a database connection. Creating a connection is a heavy process and it’s not a good idea to let every part of the program to create it’s own connection. This can lead to resource starvation and slow performance.

    That’s why we use Connection Pooling in most of the enterprise application. Most of the database drivers provide DataSource implementation classes that can be used in the connection pool.

    This tutorial provide example of MySQL and Oracle DataSource and how to use them. The article also provide details about Apache DBCP that works as a wrapper around the different DataSource implementations to achieve loose coupling.

    JDBC数据源示例

    在大多数情况下,我们寻求的不仅仅是数据库连接。 创建连接是一个繁重的过程,让程序的每个部分创建自己的连接不是一个好主意。 这会导致资源匮乏和性能降低。

    这就是为什么我们在大多数企业应用程序中使用连接池的原因。 大多数数据库驱动程序都提供可在连接池中使用的DataSource实现类。

    本教程提供了MySQL和Oracle DataSource的示例以及如何使用它们。 本文还提供了有关Apache DBCP的详细信息,该Apache DBCP用作不同DataSource实现的包装,以实现松散耦合。

  7. JDBC Transaction Management

    Transaction Management is important when we have a group of queries to execute and we want to make sure either all of them executes or none of them. We can set the connection auto commit to false, to achieve transaction management. If everything goes fine, we can commit the transaction or if there are any exceptions we can rollback the whole transaction.

    It also explains about the Savepoint that we can use to rollback to a particular point in the transaction. You can think of Savepoint as milestones in the transaction.

    JDBC事务管理

    当我们有一组查询要执行并且我们想确保所有查询都执行或都不执行时,事务管理很重要。 我们可以将连接自动提交设置为false,以实现事务管理。 如果一切顺利,我们可以提交事务,或者如果有任何异常,我们可以回滚整个事务。

    它还说明了可用于回滚到事务中特定点的保存点。 您可以将Savepoint视为交易中的里程碑。

  8. Tomcat JNDI DataSource Example

    Most of the servlet containers supports JNDI resources for DataSource that we can use to offload the transaction management and connection pooling tasks to the container. This article explains about different ways through which we can configure DataSource in Apache Tomcat server and use JNDI context lookup to get the DataSource and work with it.

    Tomcat JNDI数据源示例

    大多数Servlet容器都支持DataSource的JNDI资源,我们可以使用该资源将事务管理和连接池任务卸载到容器。 本文介绍了我们可以在Apache Tomcat服务器中配置DataSource并使用JNDI上下文查找来获取DataSource并使用它的不同方式。

  9. Spring JDBC and JdbcTemplate Example

    This article provides details of JDBC integration with Spring Framework. We can either chose to use standard JDBC API or get the benefits of Spring JdbcTemplate that helps us in removing all the boiler plate code that comes with JDBC, for example open/close connection, statement, result sets etc.

    Spring JDBC和JdbcTemplate示例

    本文提供了JDBC与Spring Framework集成的详细信息。 我们可以选择使用标准的JDBC API或获得Spring JdbcTemplate的好处,它可以帮助我们删除JDBC附带的所有样板代码,例如打开/关闭连接,语句,结果集等。

  10. Spring Transaction Management

    Spring provides built-in support for transaction management. Transaction management is a cross-cutting concerns and Spring AOP approach with declarative transaction management is very simple and elegant to use. A sample project explaining different aspects of transaction management in Spring Framework for JDBC operations.

    Spring交易管理

    Spring提供了对事务管理的内置支持。 事务管理是一个跨领域的问题,带有声明式事务管理的Spring AOP方法非常简单易用。 一个示例项目,解释了Spring Framework for JDBC操作中事务管理的不同方面。

  11. Spring DataSource JNDI Example

    Spring framework is very popular because it provides configuration based solution for most of the common tasks. That’s why spring framework provides simple configurations to lookup JNDI context and get DataSource defined by the servlet container. A tutorial with Spring MVC Example Project to show you how to do it easily.

    Spring DataSource JNDI示例

    Spring框架非常流行,因为它为大多数常见任务提供了基于配置的解决方案。 这就是为什么spring框架提供简单的配置来查找JNDI上下文并获取servlet容器定义的DataSource的原因。 Spring MVC示例项目教程,向您展示如何轻松实现。

  12. JSF JDBC Integration Example

    JSF is one of the most widely used component based framework. This tutorial explains how we can integrate JDBC API with JSF framework.

    JSF JDBC集成示例

    JSF是使用最广泛的基于组件的框架之一。 本教程说明了如何将JDBC API与JSF框架集成。

  13. JDBC Interview Questions and Answers

    A collection of 40 JDBC related interview questions with detailed answers to help you in Java interviews to conquer different kinds of JDBC questions.

    JDBC Interview Questions and Answers

    Contains a collection of 40 JDBC related interview questions with detailed answers to help you in your Java interview for various JDBC problems.

I will be adding more posts in JDBC tutorial, so please bookmark the post for future reference too.

I'll be adding more posts to the JDBC tutorial, so please bookmark this post for future reference as well.

Translated from: https://www.journaldev.com/2681/jdbc-tutorial

jdbc tutorial

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324142841&siteId=291194637