🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #23008

weblogic data sources��������

#23008
From: xml
Date: Mon, 25 Aug 2003 10:51
105 lines
4636 bytes
Դ��������
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 ("demods");
      if(ds==null){
        System.out.println("yjq null");
      }
    } 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("LOCATION") + "<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) {};
      }
    }
  }
  Context ctx;
  DataSource ds;
  Statement stmt;
  ResultSet rs;
}
�� weblogic server console��services�Ѿ����ú�connection pools "demo pool",
Ȼ������֮����������Դmyds,���JNDIΪ��demods��
������Init Error:javax.naming.NameNotFoundException:Unable to resolve"demo
ds"Resolved;remaining name"demods"
Ϊʲô������������������������

--
���費������ͥǰ�������䣬ϸƷ�����չ���ζ����߽࣬�����������ԣ�ȥ������
��������ƾ����棬��׷�����Ͼ����ˣ�־���ӣ������������֮
�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 202.120.8.25]
Technical Details
Message-ID: <4816C7$AKP@bbs.sjtu.edu.cn>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!38.144.126.76.MISMATCH!feed2.newsreader.com!newsreader.com!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!SJTU

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,GB
X-Google-Thread: f6cb0,299452747c3e201f,start
X-Google-Attributes: gidf6cb0,public
X-Google-ArrivalTime: 2003-08-25 03:53:25 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!38.144.126.76.MISMATCH!feed2.newsreader.com!newsreader.com!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!SJTU
From: soapxml.bbs@bbs.sjtu.edu.cn (xml)
Newsgroups: cn.bbs.comp.lang.java
Subject: weblogic data sources��������
Date: 25 Aug 2003 10:51:13 GMT
Organization: ��ˮ˼Դ
Message-ID: <4816C7$AKP@bbs.sjtu.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: Java/M.1061808199.A
Lines: 105