jdbc

Logging PreparedStatements in Java

One thing that always been a pain is to log SQL (JDBC) errors when you have a PreparedStatement instead of the query itself. You always end up with messages like: 2008-10-20 09:19:48,114 ERROR LoggingQueueConsumer-52 [Logger.error:168] Error executing SQL: [INSERT INTO private_rooms_bans (room_id, name, user_id, msisdn, nickname) VAL...

Database agnostic jdbc table import/export to files?

Is it at all possible to do database-agnostic table dumps/hydrates? I don't have any complicated constraints. I would also settle for db-specific ways, but the more pure jdbc it is the better (I don't want to resort to impdp/expdp). ...

How to use MySQL prepared statement caching?

How do i take advantage of MySQL's ability to cache prepared statements? One reason to use prepared statements is that there is no need to send the prepared statement itself multiple times if the same prepared statement is to be used again. Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysq...

Converting between oracle.sql.TIMESTAMPTZ and standard JDBC classes for DbUnit

I'm running Oracle 10g and have columns with Type_Name TIMESTAMP(6) WITH TIME ZONE When inflated into java classes they come out as oracle.sql.TIMESTAMPTZ But DbUnit can't handle converting Oracle specific classes to Strings for writing to XML. I'm wondering if there's any easy way for me to convert (say, in my SELECT statement so...

JDBC Thin layer encryption in Application Servers Data Sources

Hi, I came across an interesting article which shows how we can transparently encrypt jdbc connections using java thin client. http://javasight.wordpress.com/2008/08/29/network-data-encryption-and-integrity-for-thin-jdbc-clients/ However I want to know how this can be achieved for application servers (like oc4j) datasources. ...

How to get a value from the last inserted row?

Is there some way to get a value from the last inserted row? I am inserting a row where the PK will automatically increase, and I would like to get this PK. Only the PK is guaranteed to be unique in the table. I am using Java with a JDBC and PostgreSQL. ...

Should I catch exceptions thrown when closing java.sql.Connection

Connection.close() may throw SqlException, but I have always assumed that it is safe to ignore any such exceptions (and I have never seen code that does not ignore them). Normally I would write: try{ connection.close(); }catch(Exception e) {} Or try{ connection.close(); }catch(Exception e) { logger.log(e.getMessag...

Why does Char(1) change to Char(3) when copying over an Oracle DBLINK?

I have 2 databases, and I want to transport an existing table containing a CHAR column from database A to database B. Database A is Oracle 9i, has encoding WE8ISO8859P1, and contains a table "foo" with at least 1 column of type CHAR(1 char). I can not change the table on database A because it is part of a third party setup. Database B...

How to determine database type for a given JDBC connection?

i need to handle resultset returning stored procedures/functions for three databases (oracle, sybase, MS-Server). the procedures/functions are generally the same but the call is a little different in oracle. statement.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR); . . . statement.execute(); ResultSet rs = (ResultSet)statem...

jdbc: when can i close what

currently i have jdbc code with the following basic stucture: get Connection (do the next 4 lines several times, never closing statement) get statement get result set process result set close result set close connection It occurred to me after writing this code that i need to close the statement. 1 what are the effects of not cl...

Oracle single-table constant merge with CLOB using JDBC

As a follow-up to this question, I need help with the following scenario: In Oracle, given a simple data table: create table data ( id VARCHAR2(255), key VARCHAR2(255), value CLOB); I am using the following merge command: merge into data using ( select ? id, ? key, ? value fr...

ORM solutions (JPA; Hibernate) vs. JDBC

I need to be able to insert/update objects at a consistent rate of at least 8000 objects every 5 seconds in an in-memory HSQL database. I have done some comparison performance testing between Spring/Hibernate/JPA and pure JDBC. I have found a significant difference in performance using HSQL.. With Spring/Hib/JPA, I can insert 3000-400...

How disable SQL Server jdbc driver logging from a java application?

When I change the application log level to FINE, SQL Servers log also uses it, and, as consequence, I get a lot of unnecessary log messages. How can I turn off SQL Server log messages? ...

Incite database failure for integration test

When running an integration test (Web Service talking to JDBC, in this case) how do you force the database to throw an error so that the resulting soap fault can be inspected? I'm using Spring's Transactional Test Framework, so would be unreasonable to just issue a DROP TABLE whatever; to break it? :D ...

How do I unit test jdbc code in java?

I'd like to write some unit tests for some code that connects to a database, runs one or more queries, and then processes the results. (Without actually using a database) Another developer here wrote our own DataSource, Connection, Statement, PreparedStatement, and ResultSet implementation that will return the corresponding objects base...

Accessing a ColdFusion datasource from Java code

I have a servlet that I would like to run within ColdFusion MX 7. I would like to make use of an existing ColdFusion DSN as a javax.sql.DataSource, if possible. I thought something like coldfusion.server.ServiceFactory.getDataSourceService().getDatasource(dsname); would work, but unfortunately the servlet returns java.lang.NoClassD...

BCP out Error in SQL2000: SQLState = 37000, NativeError = 4060

Hi, I have created a proc that grabs all the user tables in a local DB on my machine. I want to be able to create a flat file of all my tables using BCP and SQL. Its a dummy database in SQL 2000 connecting through windows authentication. I have set my enviroment path variable in WinXP SP2. I have created new users to access the db, swi...

Understanding JDBC internals

[1] In JDBC, why should we first load drivers using Class.forName("some driver name"). Why SUN didnt take care of loading driver within the getConnection() method itself.If I pass driver name as a parameter to the getConnection() method. [2] I want to understand JBDC internals.Any pointers towards it are appreciated. ...

How to count open db connections ?

I'm developing a web app using Java servlet to access Mysql db, how can I get the number of connections to my DB that is currently open ? Edit : I tried "show processlist", it showed me : 2695159, but that's not right, I'm just developing this new project, I'm the only user, couldn't have that many processes running, what I want is the...

SQL Deletion Cascading Help (Specific Question)

I have two tables (renamed/refactored for illustrative purposes) with a Many-To-Many relationship in an HSQL database. I want everything to be wiped out when I delete from one side of a Many-to-Many relationship (without querying the table; this is performance critical) Here are my main tables: CREATE TABLE PERSON ( PERSON_ID INTE...