Open GoogleCodeExporter opened 9 years ago
https://www.liferay.com/community/wiki/-/wiki/Main/Add+Datasource+to+Portlet
Add the following line to tomcat-7.0.42/conf/context.xml
<Resource name="jdbc/oracle"
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="30"
maxWait="10000"
username="htlyktt"
password="admin"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:xe"/>
Original comment by ntanh...@gmail.com
on 18 Sep 2014 at 2:32
Using this code to get datasource
public class ConnectionDatasource {
public static DataSource datasource = null;
static {
String DATASOURCE_CONTEXT = "java:comp/env/jdbc/oracle";
try {
Context initialContext = new InitialContext();
datasource = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);
if (datasource != null) {
//result = datasource.getConnection();
System.out.println("Lookup datasource.");
//Statement stmt = result.createStatement();
}else{
System.out.println("Can not find datasource.");
}
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Original comment by ntanh...@gmail.com
on 18 Sep 2014 at 2:33
Original issue reported on code.google.com by
ntanh...@gmail.com
on 18 Sep 2014 at 1:55