Spring JDBC Tutorial
Selected Reading
- Spring JDBC - Discussion
- Spring JDBC - Useful Resources
- Spring JDBC - Quick Guide
- Spring JDBC - StoredProcedure
- Spring JDBC - SqlUpdate
- Spring JDBC - SqlQuery
- Spring JDBC - SimpleJdbcCall
- Spring JDBC - SimpleJdbcInsert
- NamedParameterJdbcTemplate
- Spring JDBC - RowMapper
- Spring JDBC - ResultSetExtractor
- PreparedStatementSetter
- Spring JDBC - JdbcTemplate
- Multiple Batches Operation
- Objects Batch Operation
- Spring JDBC - Batch Operation
- Spring JDBC - Handling CLOB
- Spring JDBC - Handling BLOB
- Spring JDBC - Calling Stored Function
- Calling Stored Procedure
- Spring JDBC - Delete Query
- Spring JDBC - Update Query
- Spring JDBC - Read Query
- Spring JDBC - Create Query
- Spring JDBC - First Application
- Spring JDBC - Configure Data Source
- Spring JDBC - Environment Setup
- Spring JDBC - Overview
- Spring JDBC - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Spring JDBC - Configure Data Source
Spring JDBC - Configure Data Source
Let us create a database table Student in our database TEST. I assume you are working with MySQL database, if you work with any other database then you can change your DDL and SQL queries accordingly.
CREATE TABLE Student( ID INT NOT NULL AUTO_INCREMENT, NAME VARCHAR(20) NOT NULL, AGE INT NOT NULL, PRIMARY KEY (ID) );
Now we need to supply a DataSource to the JDBC Template so it can configure itself to get database access. You can configure the DataSource in the XML file with a piece of code shown as follows −
<bean id = "dataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name = "driverClassName" value = "com.mysql.cj.jdbc.Driver"/> <property name = "url" value = "jdbc:mysql://localhost:3306/TEST"/> <property name = "username" value = "root"/> <property name = "password" value = "admin"/> </bean>
In the next chapter, we ll write the first apppcation using the database configured.
Advertisements