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