1 package com.github.davidmoten.rx.jdbc;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.SQLException;
6
7 import com.github.davidmoten.rx.jdbc.exceptions.SQLRuntimeException;
8
9
10
11
12
13 public final class ConnectionProviderFromUrl implements ConnectionProvider {
14
15
16
17
18 private final String url;
19
20 private final String username;
21
22 private final String password;
23
24
25
26
27
28
29
30 public ConnectionProviderFromUrl(String url) {
31 this(url, null, null);
32 }
33
34
35
36
37
38
39
40
41 public ConnectionProviderFromUrl(String url, String username, String password) {
42 this.url = url;
43 this.username = username;
44 this.password = password;
45 }
46
47 @Override
48 public Connection get() {
49 try {
50 if (username != null || password != null)
51 return DriverManager.getConnection(url, username, password);
52 else
53 return DriverManager.getConnection(url);
54 } catch (SQLException e) {
55 throw new SQLRuntimeException(e);
56 }
57 }
58
59 @Override
60 public void close() {
61
62 }
63 }