Dear All,
I am running weblogic 6.1, using Oracle 8i, and trying to follow an example from a book called,
J2EE Applications and BEA WebLogic Server, Chapter 5, Using Databases and Transactions with
JDBC and JTA, example myJDBCReadServlet.war.
I have the following settings.
Name: myConnectionPool
URL: jdbc
racle:thin:@127.0.0.1:1521:Java1
Driver Classname: weblogic.jdbc.oci.Driver
Properties
(key=value): user=system
server=Java1
ACLName:
Password: change...
and for my DataSource:-
Name: myDataSource
JNDI Name: myconnection
Pool Name: myConnectionPool
Row Prefetch Enabled
Row Prefetch Size:
Stream Chunk Size: bytes
and when I try to run the following:-
http://127.0.0.1:7001/myJDBCReadServlet I get the following error message.
<10-Jan-02 01:14:05 GMT> <Notice> <WebLogicServer> <Started WebLogic Admin Server "myserver" for domain "mydomain" running in Production Mode>
<10-Jan-02 01:14:15 GMT> <Info> <NT Performance Pack> <Allocating: '2' NT reader threads>
<10-Jan-02 01:14:21 GMT> <Info> <HTTP> <[WebAppServletContext(1713526,console,/console)] actions: init>
<10-Jan-02 01:14:28 GMT> <Info> <HTTP> <[WebAppServletContext(1713526,console,/console)] FileServlet: init>
<10-Jan-02 01:14:28 GMT> <Info> <HTTP> <[WebAppServletContext(1713526,console,/console)] FileServlet: Using standard I/O>
<10-Jan-02 01:15:09 GMT> <Info> <HTTP> <[WebAppServletContext(2230667,myJDBCReadServlet,/myJDBCReadServlet)] myJDBCReadServlet: init>
Init Error: javax.naming.NameNotFoundException: Unable to resolve myDataSource. Resolved: '' Unresolved:'myDataSource' ; remaining name ''
Service Error: java.lang.NullPointerException
<10-Jan-02 01:18:48 GMT> <Info> <Management> <Configuration changes for domain saved to the repository.>
Java source code:-
package com.learnweblogic.examples.ch5;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class myJDBCReadServlet extends HttpServlet {
/*
* This method is called when the
servlet is first initialized.
* Note here that both the initial lookup into the WebLogic JNDI
* naming context and the location of a DataSource object from it
* are placed here. This ensures that the operations are only done
* once instead of every time that the servlet is accessed. This is
* very important for efficiency.
*/
public void init() {
try {
/* Create a connection to the WebLogic JNDI Naming Service:
*/
ctx = new InitialContext();
/* Create a new DataSource by Locating It in the Naming Service:
*/
ds = (javax.sql.DataSource)ctx.lookup("myDataSource");
} catch (Exception E) {
/*
Handle exception here.
*/
System.out.println("Init Error: " + E);
}
}
public void service(HttpServletRequest requ,
HttpServletResponse resp)
throws IOException
{
Connection myConn = null;
try {
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head><title>myJDBCReadServlet</title></head>");
out.println("<body>");
out.println("<h1>myJDBCReadServlet</h1>");
/* Get a new JDBC connection from the DataSource:
*/
myConn = ds.getConnection();
/* Create an Instance of the java.sql.Statement class
and use the factory method called createStatement()
available in the Connection class to create a new statement.
*/
stmt = myConn.createStatement();
/* Use the shortcut method the available in the Statement
class to execute our query. We are selecting all rows
from the EMPLOYEE table.
*/
rs = stmt.executeQuery("SELECT * FROM EMPLOYEE ");
/* This enumerates all of the rows in the ResultSet and
prints out the values at the columns named ID, NAME,
LOCATION.
*/
while (rs.next()) {
out.println(rs.getString("ID") + "- " +
rs.getString("NAME") + "- " +
rs.getString("SEX") + "<p>");
}
/* Release the ResultSet and Statement.
*/
rs.close();
stmt.close();
} catch (Exception E) {
/*
Handle exception here.
*/
System.out.println("Service Error: " + E);
} finally {
if (rs != null) {
try { rs.close(); } catch (Exception ignore) {};
}
if (stmt != null) {
try { stmt.close(); } catch (Exception ignore) {};
}
if (myConn != null) {
try { myConn.close(); } catch (Exception ignore) {};
}
}
}
/*
* Local Variables
*/
Context ctx;
DataSource ds;
Statement stmt;
ResultSet rs;
}
I would be most greatful for anyones help, in helping resovlethis JNDI problems.
Thanks
Bob S.