Hi,
thats where the delay is from....
Your getConnection is not the way you should obtain connections in an
app-server!!! you don't use the connection-pooling stuff. do:
have a      private DataSource _dataSource;   in your class,
    private Connection getConnection() throws SQLException {
        if (_dataSource == null) {
            try {
                Context  context  = new InitialContext();
                // Whitout a proper mapping of your datasource in jboss.xml
                _dataSource = (DataSource)
context.lookup("java:/PostgresqlDB");
                // With a mapping of a resource-manager and a resource-ref
in jboss.xml (see chapter 6 of docu)
                _dataSource = (DataSource)
context.lookup("java:comp/env/jdbc/YOUR_MAPPED_NAME_HERE");
            } catch (Exception Ex) {
                throw new SQLException("getConnection failed (" +
Ex.toString() + ")");
            }
        }
        return _dataSource.getConnection();
    }
Using your connection should follow this pattern:

        Connection con=null; PreparedStatement prepStmt=null; ResultSet
rs=null;
        try {
            con = makeConnection();
            prepStmt = con.prepareStatement("SELECT * FROM table WHERE
column1 = ? AND column2 = ?");
            prepStmt.setInt(1, _SomeIntegerObject.intValue());
            prepStmt.setString(2, SomeStringObject);
            rs = prepStmt.executeQuery();
            while( rs.next() ) {
                //do something
            }
        } catch(SQLException Ex) {
            // handle exceptions
        } finally {
            if( rs!=null)       try { rs.close(); }       catch(Exception
Ex) { rs=null; }
            if( prepStmt!=null) try { prepStmt.close(); } catch(Exception
Ex) { prepStmt=null; }
            if( con!=null)      try { con.close(); }      catch(Exception
Ex) { con=null; }
        }
See how fast that is.
Burkhard
----- Original Message -----
From: "G.L. Grobe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 18, 2001 12:07 AM
Subject: Re: [JBoss-user] dbase is acting way too slow


> I'd like to verify the URL line, maybe this is my problem. I noticed that
> the name url in this post was a little different.
>
> This is the jdbc url I use to connect to my datasource ...
> "jdbc:postgresql:acais://localhost:5432". The same url used in the dbURL
of
> this portion of code.
>
>    public Connection getConnection() throws SQLException {
>       return DriverManager.getConnection(dbURL, "myUser", "myPasswd");
>    }
>
> So my lines in the <mbean>'s of jboss.jcml look like this.
>
>    <attribute
name="URL">jdbc:postgresql:acais://localhost:5432</attribute>
>
> 5432 is the port in my /etc/services file of postgres. acais is the name
of
> the dbase in postgres. It all works, it's just very slow.
>
> -----
> When the code below executes, it goes very quickly as it runs through the
> method, the the next time this method get's called ... there's a pause
> before it executes. I'm sure the code is fine, I beleive it's still a
config
> problem. It has worked fine on other servers. Otherwise the result sets
get
> returned very quickly. It's just there's a long pause as if it's trying to
> find the dbase for some reason and not accepting the config.
> ...
>      try {
>          dbConn = getConnection();
>          stmt = dbConn.createStatement();
>
>          String query = "SELECT shell FROM Shells WHERE platform_id = "
>             + platform;
>
>          System.out.println("query = " + query);
>          ResultSet rs = stmt.executeQuery(query);
>
>          int cnt = 0;
>
>          while (rs.next()) {
>             shells.put(new Integer(++cnt), rs.getString("shell"));
>          }
>       }
>
>



_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to