Spring JDBC Connection Database

Source: Internet
Author: User

1. Configuring the JDBC Bean in Applicationcontext.xml

class= "Org.springframework.jdbc.datasource.DriverManagerDataSource" >  <property name= " Driverclassname "value=" Oracle.jdbc.driver.OracleDriver "></property>  <property name=" url "value=" JDBC:ORACLE:THIN:@10.217.3.2:1521:ORCL "></property>  <property name=" username "value=" * "></ property>  <property name= "password" value= "*" ></property>  

Note: Use Spring's datasource here
Org.springframework.jdbc.datasource.DriverManagerDataSource
Optional:
Org.springframework.jdbc.datasource.SingleConnectionDataSource
Difference: drivermanagerdatasource---Create a new connection on each connection request
Singleconnectiondatasource-All returns the same connection on each connection request

2. Get DataSource Bean Object

New Classpathxmlapplicationcontext ("Applicationcontext.xml");   

3. Get the Connecting object connection and statement

Connection conn = ds.getconnection ();   = Conn.createstatement ();

4. Perform insert record operation to database

String sqlString = "INSERT into bryanttesttable values (2, ' Bryant ')";  Sm.execute (sqlString);

Spring JDBC Connection Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.