jdbc

Where to close java PreparedStatements and ResultSets?

Consider the code: PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.createStatement(myQueryString); rs = ps.executeQuery(); // process the results... } catch (java.sql.SQLException e) { log.error("an error!", e); throw new MyAppException("I'm sorry. Your query did not work."); } finally { ps.close(); rs.cl...

JDBC & MSSQL seem to be truncating large fields

I'm using jython 2.2.1, and jdbc 1.2 and connecting to a mssql 2000 database, writing the contents of an email to it. When I get to the body of the email which can be quite large sometimes I need to truncate the data at 5000 chars. Except mssql & jdbc gang up on me like school yard bullies, when i check the database loads of my data is m...

Wildcards in Java PreparedStatements

Here's my current SQL statement: SEARCH_ALBUMS_SQL = "SELECT * FROM albums WHERE title LIKE ? OR artist LIKE ?;"; It's returning exact matches to the album or artist names, but not anything else. I can't use a '%' in the statement or I get errors. How do I add wildcards to a prepared statement? (I'm using Java5 and MySQL) Thanks! ...

How to make a database service in Netbeans 6.5 to connect to SQLite databases?

I use Netbeans IDE (6.5) and I have a SQLite 2.x database. I installed a JDBC SQLite driver from zentus.com and added a new driver in Nebeans services panel. Then tried to connect to my database file from Services > Databases using this URL for my database: jdbc:sqlite:/home/farzad/netbeans/myproject/mydb.sqlite but it fails to connec...

Is Hibernate good for batch processing? What about memory usage?

I have a daily batch process that involves selecting out a large number of records and formatting up a file to send to an external system. I also need to mark these records as sent so they are not transmitted again tomorrow. In my naive JDBC way, I would prepare and execute a statement and then begin to loop through the recordset. As ...

Transaction with MonetDB and JDBC driver

I'm trying to perform transaction-like behavior with MonetDB and its JDBC driver. I tried first to set autocommit to false for the connection, I then get the following error on commit : java.lang.IndexOutOfBoundsException at java.nio.StringCharBuffer.subSequence(StringCharBuffer.java:92) at nl.cwi.monetdb.mcl.parser.StartOfHead...

SQl Query to Hibernate Query

I have a MYSQL query that I use to retrieve random rows from a table. The query is : SELECT * FROM QUESTION WHERE TESTID=1 ORDER BY RAND() LIMIT 10; Now I need to change this query to Hibernate. Did a bit of Googling but couldn't find the answer. Can someone provide help on this. Thanks ...

ODBC to JDBC datatypes mapping

Where can I find description of how to map ODBC datatypes to JDBC? Or maybe anybody knows where source code of a jdbc-odbc bridge driver can be downloaded? ...

How to set Cursor type in JDBC?

I'm running tomcat and have some jsp pages that display a subset of a table. I show 20 rows at a time on a single page. When the table has large amounts of data, the jsp page doesn't render. I'm guessing that the ResultSet is using a client side cursor. I've worked with ASP in the past, and we always used server side forward only cur...

tool for detecting non-parametrized sql in java jdbc code

I'm looking to inspect SQL statements in Java/jdbc code to ensure that the SQL to be executed is of acceptable quality. Neither PMD not Findbugs appears to have JDBC or sql rules. I could use p6spy to log the SQL and look at that way, but this is manual. I'm wondering if the strategy of of using PMD/Findbugs/etc to create a rule that ...

SQL query of multi-member file on AS400

On AS400 in interactive SQL in a 5250 session, select * from myfile returns rows from one member only when myfile has more than one member. How can I get rows from a specific member? Important: in the end I'd like to do this over JDBC with jt400 so really I want a solution that'll work there. Thanks. ...

AS400 style naming over JDBC

Is there any way I can use AS400 style library/file style naming over JDBC with jt400? I want to be able to run queries like: SELECT * FROM MYLIBRARY/MYFILE Thanks ...

AS400 library/file (member) JDBC query

Using JDBC (with jt400 driver / connection, naming=system) I'm running these SQL statements: "CREATE ALIAS QTEMP/SOURCETEMP FOR " + library + "/" + file + " (" + member + ")" "SELECT SRCDTA FROM QTEMP/SOURCETEMP" "DROP ALIAS QTEMP/SOURCETEMP" This works. However, when the member String has a . in it this confuses everthing. Is there...

How to use SQL Server Compact Edition (CE) from Java?

I want to access Microsoft SQL Server Compact Edition databases from Java. How can I do that? I searched for JDBC driver for SQLCE, but I didn't find any. ...

Java Driver.getConnection() yields "Connection Refused" from mysql on live system, not dev.

Pretty straightforward stuff, here -- I'm just not good enough with mysql to understand what it wants from me. I've got a short java test-case that opens a connection on mysql on my dev system but, when I try to put it to my server, it fails. Any help in tracking this down would be most appreciated. Thanks! Test Code import java.ut...

Tips on Speeding up JDBC writes?

I am writing a program that does a lot of writes to a Postgres database. In a typical scenario I would be writing say 100,000 rows to a table that's well normalized (three foreign integer keys, the combination of which is the primary key and the index of the table). I am using PreparedStatements and executeBatch(), yet I can only manag...

How do I map a hibernate Timestamp to a MySQL BIGINT?

I am using Hibernate 3.x, MySQL 4.1.20 with Java 1.6. I am mapping a Hibernate Timestamp to a MySQL TIMESTAMP. So far so good. The problem is that MySQL stores the TIMESTAMP in seconds and discards the milliseconds and I now need millisecond precision. I figure I can use a BIGINT instead of TIMESTAMP in my table and convert the types i...

Java NullPointerException when traversing a non-null recordset

Hello again - I am running a query on Sybase ASE that produces a ResultSet that I then traverse and write the contents out to a file. Sometimes, this will throw a NullPointerException, stating that the ResultSet is null. However, it will do this after printing out one or two records. Other times, with the same exact input, I will receiv...

Oracle JDBC Euro character

We have a problem with the Euro character when saving and retrieving it from a Oracle 10g using the Oracle 10.2.0.3 JDBC driver. The problem only occurs during a JUnit test running under Linux. The Euro characters returned from database after saving are total screwed up. Oracle has been configured to use character set "WE8MSWIN1252". Cou...

How do I dynamically replace the class loader for an Eclipse plug-in?

I am developing an Eclipse plug-in that fits a client-server model. Its a commercial project so we cannot re-distribute the JDBC drivers for the various databases we support with the plug-in. So I developed a preference page to allow the user locate the jars and have a simple discovery mechanism that iterates through the classes in the ...