-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathSimpleDriverManagerDataSource.java
More file actions
48 lines (42 loc) · 1.89 KB
/
SimpleDriverManagerDataSource.java
File metadata and controls
48 lines (42 loc) · 1.89 KB
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
package com.example;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* Simple DataSource implementation using DriverManager.
*
* <p>
* Provides basic JDBC connections using a URL, username, and password.
* Only getConnection methods are supported; other DataSource features throw
* UnsupportedOperationException.
* </p>
*/
public class SimpleDriverManagerDataSource implements DataSource {
private final String url;
private final String username;
private final String password;
/**
* Creates a new DataSource with the given JDBC parameters.
*
* @param url the JDBC URL
* @param username the database username
* @param password the database password
*/
public SimpleDriverManagerDataSource(String url, String username, String password) {
this.url = url;
this.username = username;
this.password = password;
}
@Override
public Connection getConnection() throws SQLException { return DriverManager.getConnection(url, username, password); }
@Override
public Connection getConnection(String username, String password) throws SQLException { return DriverManager.getConnection(url, username, password); }
@Override public <T> T unwrap(Class<T> iface) { throw new UnsupportedOperationException(); }
@Override public boolean isWrapperFor(Class<?> iface) { return false; }
@Override public java.io.PrintWriter getLogWriter() { throw new UnsupportedOperationException(); }
@Override public void setLogWriter(java.io.PrintWriter out) { throw new UnsupportedOperationException(); }
@Override public void setLoginTimeout(int seconds) { throw new UnsupportedOperationException(); }
@Override public int getLoginTimeout() { return 0; }
@Override public java.util.logging.Logger getParentLogger() { throw new UnsupportedOperationException(); }
}