jdbc

ResultSet.getBlob() Exception

The Code: ResultSet rs = null; try { conn = getConnection(); stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); while (rs.next()) { Blob blob = rs.getBlob("text"); byte[] blobbytes = blob.getBytes(1, (int) blob.length()); String text = new String(blobbytes); The result: java.sql.SQLExc...

How to Create Data Source without Pooling in Tomcat

I use JNDI context to create datasource for JDBC drivers in Tomcat's context.xml file like this, <Resource name="db/test" type="javax.sql.DataSource" driverClassName="com.test.jdbc.Driver" url="jdbc:fastdb://localhost:3306/session_db?autoReconnect=true&amp;connectTimeout=5000&amp;socketTimeout=5000" ...

Tomcat-6.0.18, expanded directory structure, datasource in context.xml

Environment: Tomcat-6.0.18 Oracle-Db JDK-1.6.0_1 -1- context.xml i a war file - works fine my-application.war/META-INF/context.xml: <Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver" maxActive="5" maxIdle="1" maxWait="-1" name="jdbc/dataource-name" password="pwd" type="javax.sql.DataSourc...

Displaying image in HTML and JSP code

How can I display image from database in HTML and JSP code? I wrote this code in JSP. <?xml version="1.0" encoding="UTF-8" ?> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page language="java" %> <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*"%> ...

Add description to columns using Java code

I can create a table and its columns in Java by using the statement: CREATE TABLE table_name(column1 int, column2 double, etc...) What I would like to do is to add descriptions to each of these columns with an appropriate statement, I found a stored procedure sp_addextendedproperty that looks like it can be used to accomplish this I j...

How to Make JDBC Driver Work in Java 5 & 6?

Java 6 comes with JDBC 4, which is not backward compatible with JDBC shipped with previous versions of Java. We have a JDBC driver which must support both Java 5 and Java 6. If I implement the new interfaces in the driver, it doesn't work in Java 5 because the interfaces also uses new classes. So we have 2 versions of the driver. Is the...

Preventing SQL injection without prepared statements (JDBC)

I have a database log appender that inserts a variable number of log lines into the database every once in a while. I'd like to create an SQL statement in a way that prevents SQL injection, but not using server-side prepared statements (because I have a variable number of rows in every select, caching them won't help but might hurt perf...

"Cursor is closed" error - when trying to execute an Oracle SP using JDBC

The Oracle version of our database is 10g. The stored procedure selects all the elements in a table and returns a REF CURSOR type as follows: create or replace PROCEDURE S_S_TEST( test_OUT OUT OAS_TYPES.REFCURSOR ) AS BEGIN OPEN test_OUT FOR SELECT * FROM table_p; CLOSE test_OUT; END S_S_TEST; When this sto...

When inserting a complex object into an SQL database, when should the object be broken up into its respectful tables?

Edit: In short what strategy should one use on insert and select scripts with complex objects (eg. two select calls, one for each table; a single select call with unions)? We have a database insert (postgresql) that includes a list of objects that is serialized (in text xml), and put it into a cell in a row amongst normal strings and su...

Spring JDBC connection pool and InputStream results

I am writing a webservice that allows users to post files and then retrieve them at a URL (basically think of it as the RESTful Amazon S3). The issue I came across was rather then return a byte[] from my Oracle query (Spring JDBC) I am returning an InputStream and then streaming the data back to the client in chunks. This (IMO) is a mu...

Getting the primary key value after a merge command?

Is there some way to get a value from the last inserted or updated row? I am using the merge command to do an insert or an update if the row exists. I know how to get the autogenerated key after an insert but can I get the primary key if I use the merge command? I'm using Java with JDBC and Oracle DB. ...

odd jdbc connection hanging problem : network issues? How to fix?

Hi, One of our customers has a newish problem: the application grinds to halt. Thread dump shows that all threads are hanging on network IO in jdbc calls. We/I have never seen these 'network IO' hangs. Typically a slow machine w/ DB problems has either a) one or two long-running queries or b) some type of lock/deadlock. In either of t...

prepared Statement in ejb3

Hi, i want to use prepared statement with ejb3 to insert data in oracle. is it possible to use. i try to find some example on net but i could not find any good example. Please help me to use it. or is there any other way to use parameter query (as we use ? in prepared statement) in ejb3 Thanks and regards ...

apple-jdbc-web server

Hi everyone !!! Plz i don't know if my post is in accordance with your policy...for any problem please i present all my desolations. I'm a bsc student in CIT . I have a project i which i want to use java applet and jdbc in a sort of host/client : My applet is working properly in the host but when i deploy it on apache webserver i lose ...

Java sql transactions. What am I doing wrong?

I have written the small test with sole purpose to better understand transactions in jdbc. And though I did all according to the documentation, the test does not wish to work normally. Here is table structure: CREATE TABLE `default_values` ( `id` INT UNSIGNED NOT auto_increment, `is_default` BOOL DEFAULT false, PRIMARY KEY(`id...

Java 6 Source backward-compatibility and SQL

My understanding is that in order to maintain source-compatibility, Java never introduces new methods to public interfaces, as that breaks existing clients implementing the interfaces. Java Release notes states In general, the policy is as follows, except for any incompatibilities listed further below: Maintenance releas...

Can JDBC connection strings specify multiple databases?

Here's my current connection string: jdbc:amazon;moduleName=Foobar:oracle:thin:@ab1na-orasvr.db.foobar.com:42111:ab1na But I need JDBC to access multiple databases. Can I simply append the second module name, separated by a semi-colon? ...

How to convert Oracle "TIME" to JDBC Time in query?

Oracle doesn't support the TIME datatype, but you can use DATE to store a TIME. My problem: select to_date('2009-06-30', 'YYYY-MM-DD') as "DATE", to_date('16:31:59', 'HH24:MI:SS') as "TIME" from dual yields: DATE TIME 2009-06-30 2009-08-01 when I run it through JDBC (in SQuirrel SQL, in fact). "2009-08-01" isn't a v...

How to create a table in mysql for containing 3 columns?

I want to create a table containing three string columns: The JSP page Part of JSP page (like footer, header, text) Actual value text How do I do that: from the command prompt from a Java application (Create if it doesn't exist -- how common is that?) Thanks ...

JDBC fundamental concepts, Pooling and Threading

I was always using JDBC in JavaSE on single-threaded environment. But now I need to use a connection pool and let many threads to have interaction with the database (MSSQL and Oracle) and I am having a hard time trying to make it as it seems that I am lacking some fundamental undestanding of the api. AFAIK after connect and logging a Co...