📄 springdatasource.java
字号:
package sp.demo3;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
public class SpringDataSource implements DataSource {
private DriverManagerDataSource dataSource = null;
private String url = "";
/**
* @param url The url to set.
*/
public void setUrl(String url) {
this.url = url;
}
public int getLoginTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}
public void setLoginTimeout(int seconds) throws SQLException {
// TODO Auto-generated method stub
}
public PrintWriter getLogWriter() throws SQLException {
// TODO Auto-generated method stub
return null;
}
public void setLogWriter(PrintWriter out) throws SQLException {
// TODO Auto-generated method stub
}
public Connection getConnection() throws SQLException {
if (dataSource == null) {
dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
dataSource.setUrl(this.url);
dataSource.setUsername("sa");
dataSource.setPassword("");
}
return dataSource.getConnection();
}
public Connection getConnection(String username, String password) throws SQLException {
// TODO Auto-generated method stub
return null;
}
/**
* @return Returns the dataSource.
*/
public DriverManagerDataSource getDataSource() {
return dataSource;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -