parent
df37c2c0eb
commit
cd33808ce0
@ -0,0 +1,27 @@
|
|||||||
|
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