Why i can not use mysql's connection pools in JB7
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sailing_Cai
Posted On:   Monday, August 19, 2002 04:33 PM

vod.jpx is under G:vodVod , web.xml under G:vodVoddefaultrootWEB-INF My web.xml code£º <?xml version="1.0" encoding="UTF-8"?> 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> servlet1 vod.Servlet1 servlet1 /servlet1 Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file. jdbc/MysqlDB javax.sql.DataSource Container I insert hereinafter into D:JBui   More>>

vod.jpx is under G:vodVod ,

web.xml under G:vodVoddefaultrootWEB-INF

My web.xml code£º

<?xml version="1.0" encoding="UTF-8"?>


2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">





servlet1

vod.Servlet1





servlet1

/servlet1





Resource reference to a factory for java.sql.Connection instances
that may be used for talking to a particular database that is configured in the
server.xml file.

jdbc/MysqlDB

javax.sql.DataSource

Container




I insert hereinafter into D:JBuilder7jakarta-tomcat-4.0.3confserver.xml
between





reloadable="true" crossContext="true">








user

DateBase




password

sailing




driverClassName

org.gjt.mm.mysql.Driver




driverName

jdbc:mysql://localhost/gdmovie






My Servlet1 code:


package vod;


import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import javax.naming.Context;

import javax.sql.DataSource;

import javax.naming.InitialContext;

import java.sql.Connection;




public class Servlet1 extends HttpServlet {

static final private String CONTENT_TYPE = "text/html";

Connection conn;

//Initialize global variables

public void init() throws ServletException {

}

//Process the HTTP Get request

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType(CONTENT_TYPE);

PrintWriter out = response.getWriter();

DataSource ds = null;

try{

Context initCtx = new InitialContext();

Context envCtx = (Context) initCtx.lookup("java:comp/env");

ds = (DataSource)envCtx.lookup("jdbc/MysqlDB");

//conn=ds.getConnection();

if(ds!=null)

out.println("Connection is OK!");

else

out.println("Fail!");

}catch(Exception ne){ out.println(ne);}

}

}


In jb7,whwn run the URL is£ºhttp://localhost:8080/servlet1

But the result always:Fail!


How can make it to "Connection is OK!"?

How can I use connection pools in JB7 and use Tomacat?

Thank u help very much!

   <<Less
About | Sitemap | Contact