jdbc

MySQL Data Truncation Error

I'm working with a fairly simple database, from a Java application. We're trying to insert about 200k of text at a time, using the standard JDBC mysql adapter. We intermittently get a com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column error. The column type is longtext, and database collation is UTF-8. Th...

How to accept REF cursor in JAVA without importing Oracle Package

I am writting JAVA programme using JDBC for database conntectivity , I am calling one stored procedure in that which is returning ORACLE REF CURSOR , IS there any way I can handle that without importing ORACLE PACKAGES ? ...

What is the equivalent of Oracle's REF CURSOR in Postgresql when using JDBC?

In Oracle I can declare a reference cursor... TYPE t_spool IS REF CURSOR RETURN spool%ROWTYPE; ...and use it to pass a cursor as the return value... FUNCTION end_spool RETURN t_spool AS v_spool t_spool; BEGIN COMMIT; OPEN v_spool FOR SELECT * FROM ...

Is it possible to store and retrieve a boolean value in a varchar field using Java JDBC?

Hi, quick question: my customer has a situation where he has his database with a varchar field and the corresponding jdbc code is storing/retrieving a boolean. I guess that the boolean values false and true are going to be translated to "0" and "1" but I would like to have a confirmation of this (I can't find the precise behavior speci...

What is the best way to present data from a very large resultset?

I'm writing a report view of an audit trail, and I need display this in a .jsp. What's the "best" way to get the data from the database to the screen? We're using Spring for dependency injection, Data Access Objects, and Hibernate. I can use hibernate or straight jdbc for this report. If I load all the records into memory I run out of ...

What is the best way to encrypt a clob?

I am using Oracle 9 and JDBC and would like to encyrpt a clob as it is inserted into the DB. Ideally I'd like to be able to just insert the plaintext and have it encrypted by a stored procedure: String SQL = "INSERT INTO table (ID, VALUE) values (?, encrypt(?))"; PreparedStatement ps = connection.prepareStatement(SQL); ps.setInt(id); p...

ResultSet not closed when connection closed?

I ve been doing code review (mostly using tools like FindBug) of one of our pet projects and FindBug marked following code as errorneus (pseudocode): Connection conn = dataSource.getConnection(); try{ PreparedStatement stmt = conn.prepareStatement(); //initialize the statement stmt.execute(); ResultSet rs = stmt.getRes...

Hibernate 3: unable to query PostgreSQL database

I am setting up a project using Hibernate 3.3.1 GA and PostgreSQL 8.3. I've just created a database, the first table, added one row there and now configuring Hibernate. However, even the simplest query: Criteria criteria = session.createCriteria(Place.class); List result = criteria.list(); could not be executed (empty list is returne...

Update a backend database on software update with Java

With which tool / library it is possible to update an existing database structure. On the update of the software it is also needed to change the database. Because there can be different versions of the software it should compare the current status with the target status of the database. It should: add table columns, fill it with defaul...

JDBC Database Connections in a Web App DAL

I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered design. For the Data Access Layer, what is the best way to handle creating Connection objects to call my SQL stored procedures and why? Bearing in mind I am writing a lot of the code by hand (I know I could be using Hibernate etc to do...

How to avoid storing credentials to connect to Oracle with JDBC?

Is it possible to setup a JDBC connection to Oracle without providing username/password information in a configuration file (or in any other standard readable location)? Typically applications have a configuration file that contains setup parameters to connect to a database. Some DBAs have problems with the fact that usernames and passw...

How to avoid storing passwords in the clear for tomcat's server.xml Resource definition of a DataSource?

The resource definition in tomcat's server.xml looks something like this... <Resource name="jdbc/tox" scope="Shareable" type="javax.sql.DataSource" url="jdbc:oracle:thin:@yourDBserver.yourCompany.com:1521:yourDBsid" driverClassName="oracle.jdbc.pool.OracleDataSource" username="tox" password="toxbaby" maxIdle="3" maxActive="10" removeAba...

What is the list of JConnect error-codes?

I have recently changed an application from storing the database username and password in a configuration file (gasp password stored in plain text in a config file, I know, I know). The application now asks the user to type in her username and password before it can continue. The new version of the application now has to interrogate th...

jdbc driver for Microsoft SQL Server CE(Compact Edition) 3.5

hi there, I want to be able to explore the contents of a DB for this version of the DB. I was thinking of using the Squirrel DB client (which needs a JDBC driver). Therefore, I'm looking for a JDBC type 4 driver for SQL SERVER 3.5. Can somone point me to a FREE OR open source or trial ware ? If no JDBC driver, how do MS developers ex...

Best way to validate user input JDBC?

Is there a built-in way to escape user input in java using the JDBC? Something similar to the php version mysql_real_escape() function. What's the best way to validate input? ...

Suggested JDBC books

I'm working in a medium-ish sized development group working on multiple projects and am looking to find good JDBC books for the team. Most of the developers already know the basics of JDBC, but are looking to learn best practices and more advanced topics. Topics might include: Advanced trips and tricks Patterns, and things that allow ...

Cause of No suitable driver found for...

I'm trying to unit test (JUnit) a DAO i've created. I'm using Spring as my framework, my dao (JdbcPackageDAO) extends SimpleJdbcDaoSupport. The testing class (JdbcPackageDAOTest) extends AbstractTransactionalDataSourceSpringContextTests. I've overriden the configLocations as follows: protected String[] getConfigLocations(){ return n...

How do I get the row count in JDBC?

I've executed a JDBC query to obtain a resultset. Before iterating over it, I'd like to quickly find out how many rows were returned. How can I do this with high performance? I'm using Java 6, Oracle 11g, and the latest Oracle JDBC drivers. ...

Can I connect to SQL Server using Windows Authentication from Java EE webapp?

I am currently investigating how to make a connection to a SQL Server database from my Java EE web application using Windows Authentication instead of SQL Server authentication. I am running this app off of Tomcat 6.0, and am utilizing the Microsoft JDBC driver. My connection properties file looks as follows: dbDriver = com...

Oracle merge constants into single table

In Oracle, given a simple data table: create table data ( id VARCHAR2(255), key VARCHAR2(255), value VARCHAR2(511)); suppose I want to "insert or update" a value. I have something like: merge into data using dual on (id='someid' and key='testKey') when matched then update set value = 'someValue' w...