Place the oracle database driver (ojdbc14.jar) in C:JBossjboss-5.1.0.CR1serverdefaultlib
Create the datasource xml file and place it in C:JBossjboss-5.1.0.CR1serverdefaultdeploy
oracle-ds.xml
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@192.168.96.95:1521:orcl</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>scott</user-name>
<password>tiger</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<check-valid-connection-sql>select * from dual</check-valid-connection-sql>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
Start the server
run -c default
Deploy the application that uses a datasrouce
index.jsp
<%@ page import=”java.sql.Connection”%>
<%@ page import=”java.sql.ResultSet”%>
<%@ page import=”java.sql.SQLException”%>
<%@ page import=”java.sql.Statement”%>
<%@ page import=”java.util.Properties”%>
<%@ page import=”javax.naming.Context”%>
<%@ page import=”javax.naming.InitialContext”%>
<%@ page import=”javax.naming.NamingException”%>
<%@ page import=”javax.sql.DataSource”%>
<%
Context ctx = null;
try {
Properties prop = new Properties();
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,”org.jnp.interfaces.NamingContextFactory”);
prop.setProperty(Context.SECURITY_PRINCIPAL,”admin”);
prop.setProperty(Context.SECURITY_PRINCIPAL,”SECURITY_CREDENTIAL”);
prop.setProperty(Context.PROVIDER_URL, “jnp://localhost:1099”);
ctx = new InitialContext(prop);
DataSource ds = (DataSource) ctx.lookup(“java:OracleDS”);
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(“select * from dual”);
rset.close();
stmt.close();
conn.close();
}catch (Exception e) {
System.err.println(e.getMessage());
}
%>
Test the application!
This is realy a good post…
Helped me a lot…
Thanks
Thanks Vamsi!!
This is really a good post…
Helped me a lot…
Thanks
HEy!!!
So thank u!!! It was amazing!!!
The warning that I had in Jboss so many days, was easy!!!
thanks 🙂
HI,
i am getting the following error when i configure the datasource.
ERROR [org.jboss.security.auth.spi.UsersRolesLoginModule] (ResourceContainer.invoker.nonDaemon-16) Failed to load users/passwords/role files
java.io.IOException: No properties file: users.properties or defaults: defaultUsers.properties found
can you please share your datasource configurations?