jdbc

How effective is executeBatch on a Prepared Statement?

Subject to this question, asks it all:How effective is executeBatch method? Is there a performance benchmark, that says.. 'if you have 1000 records to be inserted, using a executeBatch instead of executeUpdate saves you x amount of database cycles?' Or Is this just a convention? EDIT: Here is what I am working with: a DB2 V 8.1 hoste...

Connection Pooling - How much of an overhead is it?

I am running a webapp inside Webpshere Application Server 6.1. This webapp has a rules kind of engine, where every rule obtains its very own connection from the websphere data source pool. So, I see that when an use case is run, for 100 records of input, about 400-800 connections are obtained from the pool and released back to the pool. ...

Clean up repetitive setup and cleanup Java(JDBC) code

I've too many methods that repeatedly do something like Statement stmt = null; ResultSet rstmt = null; try { stmt = conn.createStatement(); rstmt = stmt.executeQuery(...); while (rstmt.next()) { //handle rows } } catch (SQLException e) { //handle errors } finally { try {rstmt.close();} catch (SQLException...

Is there a set of stubs/mocks for JDBC available anywhere?

For the past few years I've continuously struggled with unit testing database code and all the pain that comes with it. I found this existing thread which I found very enlightening: What's the best strategy for unit testing databases? The author of the accepted answer suggests that it might be useful to mock the entire database layer...

jdbc4 CommunicationsException

I have a machine running a java app talking to a mysql instance running on the same instance. the app uses jdbc4 drivers from mysql. I keep getting com.mysql.jdbc.exceptions.jdbc4.CommunicationsException at random times. Here is the whole message. Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.ex...

When to 'IN' and when not to?

Let's presume that you are writing an application for a retail store chain. So, you would design your object model such that you would define 'Store' as the core business object and lots of supporting objects. Let's say 'Store' looks like follows: class Store implements Validatable{ int storeNo; int storeName; ... etc.... } So, your ...

SimpleJdbcTemplate and null parameters

I'm using SimpleJdbcTemplate and MapSqlParameterSource in the folowing way: MapSqlParameterSource parameterSource = new MapSqlParameterSource(); parameterSource.addValue("typeId", typeId, Types.BIGINT); List<Long> ids = _jdbcTemplate.query(_selectIdByParameters, new EntityIdRowMapper(), parameterSource); When typeId ( which is a Long...

JDBC Connection closed by peer (weird)

Hi all, I'm facing sort of a strange issue with two applications of mine. Here's the setting: Two tomcat / java apps, running in the same network, connecting to the same MS-SQL-Server. The one app, which happens to be in an DMZ in order to be accessible from the internet uses to produce "jdbc Connection closed by peer" exceptions in un...

JDBC connect string for SQL Server cluster

I need to setup a JDBC connection string to SQL Server. This question is similar to the the C# ADO.Net connection question. This one is specific to JDBC connection strings. The usual format for the JDBC string is "jdbc:sqlserver://{host}:{port}". Now, for a SQL server cluster I have a cluster name vvv\iii ({virtual server}{instance nam...

can Use Hibernate and Tomcat Connection pool at same time?

Hi every one, I have a java web Application and I use Tomcat connection pooling for it, this my setting: <?xml version="1.0" encoding="UTF-8"?> <Context path="" docBase="" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/jdbcPool" auth="Container" type="javax.sql.DataSource" maxAc...

Possible memory leak due to not using StringBuffer?

Can the following code cause a memory leak? Would using a StringBuffer actually improve memory usage? A little background: A coworker has been pushing his theories on memory leaks, and this is code he has identified as being problem code (without doing any sort of profiling), which he claims can cause a memory leak. I disagree with this...

how to access multiple users' database via JDBC

Hi, I have an account in oracle database. I can connect it via jdbc in my java code. When I access database from Oracle SQL Developer, under "Connections"->"Other Users", I can access to their tables (I have been assigned privilege for reading others tables). My question is, how to access / retrieve data from others tables via jdbc? ...

JDBC postgres query with a timeout

Unfortunately setTimeout is not implemented for JDBC/postgres. Is there some way I can simulate or workaround this? Functionally I want to execute the query and the then break if it takes longer than N seconds ...

ResultSet and Select * Performance

I am refactoring some Spring JDBC code in which some of the costlier queries do "SELECT * FROM..." - and was about to start checking which columns were actually needed and just SELECT x , y FROM.. them. But reading through the ResultSet class is seemed that most data is lazily loaded. When you do a ResultSet.next() it moves the cursor ...

large sql resultsets in java

How can I fetch large resultset in java? I have about 140,000 rows with 3 columns. ...

JDBC postgres statement_timeout

Suppose I have: untimedStatement = connection.createStatement() ; timedStatement = connection.createStatement(); And then run timedStatement.execute("SET statement_timeout TO " + timeout); Will the SET statement_timeout command also affect untimedStatement? I was hoping it would not but some of the behaviour I'm observing suggests...

Multithreaded JDBC

Architecturally what is the best way to handle JDBC with multiple threads? I have many threads concurrently accessing the database. With a single connection and statement I get the following error message: org.postgresql.util.PSQLException: This ResultSet is closed. Should I use multiple connections, multiple statements or is there a...

How can I set up a JDBC connection to an OpenOffice Database odb file?

For instructional purposes, I want to set up a database in a Linux environment, then conenct to it using JDBC. OpenOffice looks a lot simpler thatn MySQL, but I'm not sure how to get the connection to it set up. ...

Question about SQL catalogs - What exactly are they?

Something that has been puzzling me for a bit now, and an hour or two of googlin' hasn't really revealed any useful answers on the subject, so I figured I'd just write the question. When I create a database in SQL using 'CREATE DATABASE DBNAME' am I implicitly creating a catalog in that database? Is it proper to refer to that 'DBNAME' a...

JDBC PoolingDataSource vs PoolingDriver

With reference to apache commons dbcp, what is the difference between PoolingDataSource and PoolingDriver? The source code states "Note that this example is very similiar to the PoolingDriver example. In fact, you could use the same pool in both a PoolingDriver and a PoolingDataSource" However it does not explicit state the differenc...