parent
d51177a01b
commit
406bbbda5f
@ -1,27 +0,0 @@
|
|||||||
package com.dao;
|
|
||||||
import java.sql.*;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import javax.naming.*;
|
|
||||||
public interface Dao {
|
|
||||||
public static DataSource getDataSource(){
|
|
||||||
DataSource dataSource = null;
|
|
||||||
try {
|
|
||||||
Context context = new InitialContext();
|
|
||||||
dataSource =
|
|
||||||
(DataSource)context.lookup("java:comp/env/jdbc/webstoreDS");
|
|
||||||
}catch(NamingException ne){
|
|
||||||
System.out.println("异常:"+ne);
|
|
||||||
}
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
public default Connection getConnection() throws SQLException {
|
|
||||||
DataSource dataSource = getDataSource();
|
|
||||||
Connection conn = null;
|
|
||||||
try{
|
|
||||||
conn = dataSource.getConnection();
|
|
||||||
}catch(SQLException sqle){
|
|
||||||
System.out.println("异常:"+sqle);
|
|
||||||
}
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue