Bonjour,
je souhaiterai le plus simplement du monde me connecter à une base de données en utilisant Spring.
J'ai actuellement :
1 fichier xml comportant mes informations de connexions.
1 fichier comportant mes requêtes sql.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>oracle.jdbc.OracleDriver</value> </property> <property name="url"> <value>jdbc:oracle:thin:@xxxx.com:1111:VIEW</value> </property> <property name="maxWait"> <value>1000</value> </property> <property name="username"> <value>USER</value> </property> <property name="password"> <value>USER_PASS</value> </property> <property name="poolPreparedStatements"> <value>false</value> </property> <property name="maxOpenPreparedStatements"> <value>0</value> </property> </bean> </beans>
1fichier xml au niveau de mon fichier de requêtes sql.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import org.springframework.jdbc.core.support.JdbcDaoSupport; public class toto extends JdbcDaoSupport{ public boolean create(to obj) { return false; } public boolean delete(to obj) { return false; } public Ip find(int id_toto,int count, String titi ) { To to = new To(); String requete; try { if (titi == "heureux"){ requete = "SELECT * FROM to WHERE id_toto = 'content'"; } else {requete = "SELECT * FROM to WHERE id_toto = 'content' AND titi = 'heureux'";} ResultSet result = this.__connect.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY ).executeQuery(requete); } catch (SQLException e) { e.printStackTrace(); } return to; } public boolean update(To obj) { return false; } }
Comment établir des liens etc... afin que lors d'une exécution de mon projet tout se passe bien ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans><import resource="dao.xml"></import> <bean id="totodao" class="dao.totodao"> <property name="dataSource" ref="dataSource"></property></bean> </beans>
Merci.
Partager