Is there Session in java's webservice?

I wanna store my database connection in a global variable,
for example, a Session or an Application,
what can I do?

Thank you very much!
I search a java file named DBConnectionManager.java which could do the job.
The source code is below:
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
//����DBConnectionManager
public class DBConnectionManager {
static private DBConnectionManager instance;
static private int clients;
private Vector drivers = new Vector();
private PrintWriter log;
private Hashtable pools = new Hashtable();
//��������������
static synchronized public DBConnectionManager getInstance() {
if (instance == null) {
instance = new DBConnectionManager();
clients++;
return instance;
//����������
private DBConnectionManager() {
init();
//������������
//������������
public void freeConnection(String name, Connection con) {
DBConnectionPool pool = (DBConnectionPool) pools.get(name);
if (pool != null) {
pool.freeConnection(con);
//����������������
//������������
public Connection getConnection(String name) {
DBConnectionPool pool = (DBConnectionPool) pools.get(name);
if (pool != null) {
return pool.getConnection();
return null;
public Connection getConnection(String name, long time) {
DBConnectionPool pool = (DBConnectionPool) pools.get(name);
if (pool != null) {
return pool.getConnection(time);
return null;
//����getconnection
//������������
public synchronized void release() {
if (--clients != 0)
return;
Enumeration allPools = pools.elements();
while (allPools.hasMoreElements()) {
DBConnectionPool pool = (DBConnectionPool) allPools.nextElement();
pool.release();
Enumeration allDrivers = drivers.elements();
while (allDrivers.hasMoreElements()) {
Driver driver = (Driver) allDrivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
log("����JDBC��������" + driver.getClass().getName());
catch (SQLException e) {
log(e, "��������JDBC��������������" + driver.getClass().getName());
private void createPools(Properties props) {
Enumeration propNames = props.propertyNames();
while (propNames.hasMoreElements()) {
String name = (String) propNames.nextElement();
if (name.endsWith(".url")) {
String poolName = name.substring(0, name.lastIndexOf("."));
String url = props.getProperty(poolName + ".url");
if (url == null) {
log("����������" + poolName + "������URL");
continue;
String user = props.getProperty(poolName + ".user");
String password = props.getProperty(poolName + ".password");
String maxconn = props.getProperty(poolName + ".maxconn", "0");
int max;
try {
max = Integer.valueOf(maxconn).intValue();
catch (NumberFormatException e) {
log("������������������" + maxconn + ".������" + poolName);
max = 0;
DBConnectionPool pool = new DBConnectionPool(poolName, url, user,
password, max);
pools.put(poolName, pool);
log("��������������" + poolName);
private void init() {
InputStream is = getClass().getResourceAsStream("/db.properties");
Properties dbProps = new Properties();
try {
dbProps.load(is);
catch (Exception e) {
System.err.println("������������������������db.properties������CLASSPATH��");
return;
String logFile = dbProps.getProperty("logfile", "DBConnectionManager.log");
try {
log = new PrintWriter(new FileWriter(logFile, true), true);
catch (IOException e) {
System.err.println("������������������" + logFile);
log = new PrintWriter(System.err);
loadDriver(dbProps);
createPools(dbProps);
private void loadDriver(Properties props) {
String driverClasses = props.getProperty("drivers");
StringTokenizer st = new StringTokenizer(driverClasses);
while (st.hasMoreElements()) {
String driverClassName = st.nextToken().trim();
try {
Driver driver = (Driver) Class.forName(driverClassName).newInstance();
DriverManager.registerDriver(driver);
drivers.addElement(driver);
log("����������������" + driverClassName);
catch (Exception e) {
log("����������������:" + driverClassName + ",����" + e);
private void log(String msg) {
log.println(new Date() + ":" + msg);
private void log(Throwable e, String msg) {
log.println(new Date() + ":" + msg);
e.printStackTrace(log);
class DBConnectionPool {
private int checkOut;
private Vector freeConnections = new Vector();
private int maxconn;
private String name;
private String password;
private String URL;
private String user;
public DBConnectionPool(String name, String URL, String user,
String password, int maxconn) {
this.name = name;
this.URL = URL;
this.password = password;
this.user = user;
this.maxconn = maxconn;
public synchronized void freeConnection(Connection con) {
freeConnections.addElement(con);
checkOut--;
notifyAll();
public synchronized Connection getConnection() {
Connection con = null;
if (freeConnections.size() > 0) {
con = (Connection) freeConnections.firstElement();
freeConnections.removeElementAt(0);
try {
if (con.isClosed()) {
log("��������" + name + "������������");
con = getConnection();
catch (SQLException e) {
log("��������" + name + "������������");
con = getConnection();
else if (maxconn == 0 || checkOut < maxconn) {
con = newConnection();
if (con != null) {
checkOut++;
return con;
public synchronized Connection getConnection(long timeout) {
long startTime = new Date().getTime();
Connection con;
while ( (con = getConnection()) == null) {
try {
wait(timeout);
catch (InterruptedException e) {}
if ( (new Date().getTime() - startTime) >= timeout) {
return null;
return con;
public void release() {
Enumeration allConnections = freeConnections.elements();
while (allConnections.hasMoreElements()) {
Connection con = (Connection) allConnections.nextElement();
try {
con.close();
log("����������" + name + "��������");
catch (SQLException e) {
log(e, "��������������" + name + "��������");
freeConnections.removeAllElements();
private Connection newConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(URL, user, password);
log("������" + name + "����������������");
catch (SQLException e) {
log(e, "������������URL������" + URL);
return null;
return con;
}

Similar Messages

  • How to pass serialized session/usertoken to BO webservice from xcelsius?

    I wonder how to pass serialized session/usertoken to BO webservice from xcelsius. Could anyone help me how to pass the serialized session/user token to BO web service from Xcelsius?
    Xcelsius is working fine when i use the username/password. But i would like to pass serialized session/usertoken from jsp file to Xcelsius as flash variable , then i will use this variable to get the data from webservice.
    Is that possible to send serialized session/usertoken using soap header?
    Thanks in advance...

    Hi Micheal
    Thank you for the reply.  I have already created the CELogonToken Flash Variable and i am able get the logon token and map to the flash variable.
    Now i would like to pass the same to biws as parameter. But the service has only 2 parameters as username and password.
    Is there a way that i can create my custom parameters(CELogonToken/CESerializedSession) in BIWS service?

  • Are there problems if we develop webservices with 1.4.2, but use 1.5.0?

    Hi all,
    I hope you may help me in one question.
    We develop webservices for IBM WAS 6.0 (java 1.4.2) with connection to oracle 9i and WMQ 5.3CDS12.
    But now we want to change the environment to IBM WAS 6.1 (including java 1.5.0).
    Are there problems if we develop webservices with 1.4.2 but using java 1.5.0 on websphere?
    Or should we use java 1.4.2 on websphere app server 6.1? I think WAS don't run under 1.4.2?!
    I hope you can help me.
    Thank you.
    SY,
    Marc

    You only need a new certificate when the old one expires. Changing JDKs has nothing to do with it.

  • Session block java.lang.IllegalStateException

    hello all
    i had developed a jsp but it gives the following error
    session block java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
    shd i paste code here?
    regards and tanks in advance
    hema

    The error is fairly self explanatory.
    "Cannot call sendRedirect() after the response has been committed "
    Once you start sending a response, you can't suddenly change your mind. JSP pages have a "buffer" to give you some leeway. The default buffer size is 8kb.
    The response is committed when the buffer is flushed. This happens when:
    - the buffer gets full
    - you explicitly call flush()
    There are two possible solutions
    1 - Make sure all forward/redirects happen as close to the top of the page as possible. This means they have a good chance of happening before the buffer gets full
    2 - make the buffer larger <%@ page buffer="16kb" %>
    Also after you do a forward/redirect, then make sure you return directly after it. Just because you call redirect, doesn't mean the page stops executing.
    Cheers,
    evnafets

  • Fedora 13: After upgrading from FF3.6 to FF6.0.2 I no longer have a Java plugin. How do I configure the Java Plugin for FF 6 ? There is no Java Plugin at the site

    I am Fedora 13x64 bit. I just installed FF v6.0.2 from the FF download site. I backed up the existing FF 3.6 as firefox_old
    I need to have a Java plugin to access company site, how do I configure the Java Plugin ?
    At the Plugin area in FF6 there is no Java Plugin available, even after a search.
    I have Java 1.6.0 installed in the OS at:
    /usr/lib/jvm/java-1.6.0/jre/lib/amd64/libnpjp2.so
    I googled how to configure Java Plugin for FF 6 for Fedora 13 and the trick was to create a soft link from /home/<userID>/.mozilla/plugins to the above libnpjp2.so

    AVtech wrote:
    . . . If a person can't get an answer here I don't know where else to turn since Sun certainly wouldn't offer tech support for a free product . . .These forums are user forums, and only occasionally visited by Sun employees. Sun does provide Java technical support options, although (of course) at a charge.
    See:
    http://developers.sun.com/services/
    . . . I guess we'll just use JRE 5 until it's unsupported, whenever that will be. I'm still waiting for an answer on that question, too. See:
    http://java.sun.com/products/archive/eol.policy.html
    http://www.sun.com/service/eosl/
    This document (part IV and Appendix) has some debugging and troubleshooting information that may allow someone involved in the problem to resolve the cause:
    See:
    http://java.sun.com/javase/6/docs/technotes/guides/plugin/developer_guide/contents.htm
    Any steps that you can take to isolate the problem to specific Java versions, browsers, applets, web sites, operating systems (and versions), etc, would enhance the possibility of getting help.
    You can try the applets at this Sun location and see if any of them are "slow".
    See:
    http://java.sun.com/javase/6/docs/technotes/samples/demos.html

  • Could not deserialize session data, java.io.InvalidClassException

    Whenever I click on logout link from Liferay(Which deployed as application on Weblogic 10.3),It shows below Exception in the console however i am able to logout sucessfully.
    Could not deserialize session data.
    java.io.InvalidClassException: org.hibernate.proxy.pojo.javassist.SerializableProxy; local class incompatible: stream classdesc serialVersionUID = 1180036893511205383, local class serialVersionUID = -2265249369383210104 at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:560)
    It seems to be Classpath polluted with different hibernate jars.But still not able to figure it out.Below is the jar files which i have in classpath.
    hibernate-annotations.jar
    hibernate-commons-annotations.jar
    hibernate-core.jar
    hibernate3.jar
    Application Server: Weblogic 10.3
    Any Help would be much appreciated.

    Sounds like you have two different versions of a class in the two applications.
              If you change a class implementation and recompile - the updated class gets a new UID. Looks like maybe one app has a jar with the older class and the other app has a jar with the new class.

  • Session in java swing??

    Hi friends,
    I need to create session in java swing...
    I have a client running in swing and can access resources in multi-threaded server. I need to validate user using session. But i don't know how to use session.
    User has to login with username & password (authentication verified at server using socket communication).
    If successful the login frame vanishes and other options are displayed. user has a feature that he can send files to other
    user. so i need to use session for security purpose.
    Anyone help me with code
    Edited by: sathya_vn on Apr 20, 2008 5:41 PM

    Anyone help me with the code-----> u got tat wrong..
    I need to know how to use session with java swing. I requested if anyone has such code....
    This is a part of my project .
    Am using MySQL Database to store username and password.
    Cleint side interface has a frame (first frame--frame1) requesting client to provide login information. The login details <username and password> are sent to server. server validates whether the login info are correct or not and return true or false .
    If false the frame1 will show a JOptionPane ... message stating that wrong username or password specified.
    If true i need to create a session and other operations are done after session validation. I am using ssl socket.
    If u want the code then i have post around 300 or more lines..

  • Is There A Pure Java Solution?

    Is there a pure Java solution for a servlet to create
    a popup window? In other words, is there a Java solution
    for creating a new window with Java code inside the
    doPost() method?

    Try setting
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
    and stream html with javascript to pop a window. Don't have code right now...but try to search in this direction. Sure you can do...I will post the code if I find..
    -

  • How many classes are there in the java kit?

    i figured this was the most "general" forum to post this question in. and im curious to know, how many packages/classes/functions are there in the java sdk? like, all the prebuilt ones. ive looked but cant seem to find any info on it. anybody happen to know?
    Thanks!

    there are at least 4142 classes in the 1.4.2.x distribution ...Is that the number of files which end in .java? There's bound to be a lot more
    classes, when you u consider inner classes and especially anonymous
    inner classes.It was just a rough estimation ... and I wrote 'at least' 4142 classes ...
    and I was wrong: there are alse 4 .h files in the src.zip file, so that makes 4138
    classes at least :-)
    kind regards,
    Jos

  • Is there a free java based forum that does NOT require disk write access ?

    Hello,
    I've been trying to set up mvnForum (www.mvnForum.com) on my site but I've had to give it up as the way the server is set up I can only give write access to Tomcat if I give write access to everyone !
    I don't need my forum to have disk access as it can just use the mySQL database the whole time. So is there a good java based forum out there that does not require disk access ? I'm hoping to find one that has e-mail authentication for people who register and things like that.
    I know a php forum that will do it already but as the rest of the site is written in jsp it would be nice to be able to integrate it properly. Any help greatly appreciated.

    Please try mvnForum beta3, it doesnot require disk write. Since RC1 mvnForum use disk access to write Lucene search index and attachment file.
    Regards,
    Minh Nguyen
    mvnForum Developer

  • Is there session number digit limit ?

    Hello...
    Our job session number in Operator has 14-digit number(Ex. 14011912387).
    Is there session number digit limit?
    If a number reachs the end of column length, is a session number restarted from the first like round-robin?
    Regards,
    jenny

    Its not restarted from 0. You will have to manually set it.
    https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=424331.1

  • Is there elseif in java??

    is there elseif in java??

    Seriously on Java Tiger revision they are implementing the import static.
    This will allow, for example to do:import static java.lang.Math.*;or something like that.
    That will allow lazy coders, like me :), to skip some repeting names.
    Instead of doing:Math.pow(x, Math.sqrt(x)*Math.log(x));this:pow(x, sqrt(x)*log(x));Convenient and readable, huh?

  • I am in the process of doing a Proof Of Concept / Evaluating products that can help us build a Java Application to Convert a PDF document to a Searchable PDF.   I wanted to check is there any simple JAVA API from Adobe to achive this ? Any direction in th

    I am in the process of doing a Proof Of Concept / Evaluating products that can help us build a Java Application to Convert a PDF document to a Searchable PDF. 
    I wanted to check is there any simple JAVA API from Adobe to achive this ? Any direction in this regard is greatly appreciated.@

    You can achieve this using LiveCycle PDF Generator JAVA API. You can find required code here:
    Adobe LiveCycle * Quick Start (SOAP mode): Converting a Microsoft Word document to a PDF document using the Java API
    In parameters:
    //Set createPDF2 parameter values
    String adobePDFSettings = "Standard";
    String securitySettings = "No Security";
    String fileTypeSettings = "Standard OCR";
    "Standard OCR" file type setting will run OCR on input pdf. In the code, instead of doc file provide a pdf file. Resultant pdf will be searchable PDF i.e OCRed PDF.
    Feel feel to ask any further questions.

  • Is there any pure Java OS for PC ?

    When i testing programe with applet, i found that the performance is not good at all, i think that if there pure native java os here, i can run directly with my class file, is it already be true ?

    i dont think anyone can write an OS purely in java.You are wrong. Mainly because the question isn't very specific. I had the same opinion until someone in another thread convinced me. The solution is not the one you are thinking of. Search for the thread and read the entire thing.
    first question to answer is How good is java's IO? is
    it atleast half as good as that of C? No.Huh? Many implementations that use the Java API library could be improved if the authors took time to write a bettern implementation specific to their library. Or in some cases just used the API correctly in the first place. There is at least one magazine article that points this out.

  • Is there any core java tutorial form sun site

    HI all,
    is there any core java tutorial form sun site where i can down load it study them on offline rather that seeing it on line.
    can any give me link for it.........
    vijay

    thank you for reply ,
    i have googled and find this help full in getting the details and u can download from here.
    "http://java.sun.com/docs/books/tutorial/information/download.html"
    vijay

Maybe you are looking for

  • Crystal Reports 2008 parameter panel discrepancy.

    Hi, I have a report designed using Crystal Reports 2008. The report has a dynamic parameter called Location which is populated from a table. It is a Value - Description pair so it is: Value = LocID Descripition = LocationName. The Show on Viewer(Pane

  • Problen with dual core and sound blaster audigy 2

    HI. Installing drivers for windows XP 32 or windows 64 in both cases when I play an MP3 file or playing any games when it starts i heard a terrible noise and after a few seconds sounds normal. The problem is basically at starting mp3 songs or any pro

  • Flash Player 11 Fails Download

    I have Windows 7, IE 10 and/or Firefox 22.  Can't get flashplayer 11 to download via either web browser.  I was able to download (manually) the player, and it shows as installed in my control panel but IE does not recognize that it's installed. I nee

  • Itunes Library is Pink?

    I updated my Itunes and when it reopened it had shades of pink everywhere. Most predominant in my library page. Kind of goes back to normal when I go to the Itunes store. Any help to get this fixed would be greatly appreciated!!!

  • TestStand (Shared Object) in show step in variable tab.

    After selecting show step in variable context (tab) during execution, expanding the selected step I see the following, (plus more):   +TS (Shared Object)                              Step Type TEinf (Container) What does (Shared Object) mean? I poste