Bonjour, je suis passé à tomcat 7.0.23 et depuis il est impossible pour moi d'établir une connection avec my SQL. Voici mes classes
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
46
47
48
49
50
51
52
53
54
55
56
57
58 package data; import java.sql.*; import javax.sql.DataSource; import javax.naming.InitialContext; public class ConnectionPool { private static ConnectionPool pool = null; private static DataSource dataSource = null; private ConnectionPool() { try { InitialContext ic = new InitialContext(); dataSource = (DataSource) ic.lookup("java:/comp/env/jdbc/murach"); } catch(Exception e) { e.printStackTrace(); } } public static ConnectionPool getInstance() { if (pool == null) { pool = new ConnectionPool(); } return pool; } public Connection getConnection() { try { return dataSource.getConnection(); } catch (SQLException sqle) { sqle.printStackTrace(); return null; } } public void freeConnection(Connection c) { try { c.close(); } catch (SQLException sqle) { sqle.printStackTrace(); } } }
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 package data; import business.Clswisloo; import java.sql.*; import java.io.File; import java.io.InputStream; import business.*; public class PageDB { public static int insert(Clswisloo clswisloo) { ConnectionPool pool = ConnectionPool.getInstance(); Connection connection = pool.getConnection(); PreparedStatement ps = null; String query = "INSERT INTO TABPAGE (Nomtab, Contenutab, Imgtab, ImgLink) " + "VALUES (?, ?, ?, ?)"; try { ps = connection.prepareStatement(query); ps.setString(1, clswisloo.getNomtab()); ps.setString(2, clswisloo.getContenutab()); ps.setString(3, clswisloo.getImgtab()); ps.setString(4, clswisloo.getImgtab()); return ps.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); return 0; } finally { DBUtil.closePreparedStatement(ps); pool.freeConnection(connection); } } }
Partager