You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
769 B
28 lines
769 B
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;
|
|
}
|
|
}
|