forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSource.java
More file actions
38 lines (34 loc) · 795 Bytes
/
Copy pathDataSource.java
File metadata and controls
38 lines (34 loc) · 795 Bytes
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
import java.sql.Connection;
import org.apache.commons.dbcp.BasicDataSource;
public class DataSource
{
Connection connection = null;
BasicDataSource bdSource = new BasicDataSource();
public DataSource()
{
bdSource.setDriverClassName("com.mysql.jdbc.Driver");
bdSource.setUrl("jdbc:mysql://localhost:3306/RamJ2EE");
bdSource.setUsername("root");
bdSource.setPassword("root");
}
public Connection createConnection()
{
Connection con = null;
try
{
if( connection != null )
{
System.out.println("Cant create a New Connection");
}
else
{
con = bdSource.getConnection();
}
}
catch( Exception e )
{
System.out.println("Error Occured " + e.toString());
}
return con;
}
}