jdbc

How to connect to MySQL from a JSP?

I have installed MySQL Server 4.1 and mysql-connector-java-3.0.17-ga. I have the JSP code just to establish a connection. When I try to execute it, it throws java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. Which file am I missing and where should I place it? Thanks in advance. ...

Why ‘No database selected’ SQLException?

why this program is not executing when it goes in to the do while loop second time and why it is giving the exception "Exception java.sql.SQLException: [MySQL][ODBC 5.1 Driver][mysqld-5.0.51a-community-nt]No database selected" //import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Result...

Is using a Java Datasource an expensive ordeal?

My Java (non-Web) application may have to create Connection Pools of about 200 different Datasources. Yes, all 200 of them connecting to different Databases. Not 200 connections in the pool. Here are some questions that are bugging me.. 1) Should I anticipate major (performance etc. issues? 2) Are there any Non-commercial Java tools ...

Getting the size (in bytes) of the ResultSet using java code

How to get the size(in bytes) of the given ResultSet within the java code. Is there any direct way to find out? ...

Java JDBC driver and TYPE_FORWARD_ONLY

Hi, How I could determine if JDBC driver is TYPE_FORWARD_ONLY? In my program the user configures connection parameters to database and he could use any JDBC driver in the class path. I want to know if the driver is TYPE_FORWARD_ONLY before executing any statements. Is this possible? ...

Prevent jdbc from padding strings on sql insert and update

We are using the jdbc-odbc bridge to connect to an MS SQL database. When perform inserts or updates, strings are put into the database padded to the length of the database field. Is there any way to turn off this behavior (strings should go into the table without padding)? For reference, we are able to insert field values that don't c...

Oracle10 and JDBC: how to make CHAR ignore trailing spaces at comparision?

I have a query that has ... WHERE PRT_STATUS='ONT' ... The prt_status field is defined as CHAR(5) though. So it's always padded with spaces. The query matches nothing as the result. To make this query work I have to do ... WHERE rtrim(PRT_STATUS)='ONT' which does work. That's annoying. At the same time, a couple of pure-...

Is it possible to refer to column names via bind variables in Oracle?

I am trying to refer to a column name to order a query in an application communicating with an Oracle database. I want to use a bind variable so that I can dynamically change what to order the query by. The problem that I am having is that the database seems to be ignoring the order by column. Does anyone know if there is a particula...

SQL: Batching statements with bound variables.

I'm looking to reduce the round-trips in my application to improve performance. I want to use PreparedStatements for their multitude of benefits. This is an example of what I've come up with.. generalized with details elided.. Class.forName( "..Driver" ); Connection connection = DriverManager.getConnection( .. ); PreparedS...

In JDBC, why do parameter indexes for prepared statements begin at 1 instead of 0?

Everywhere else in Java, anything with an index starts at 0. Is there a reason for the change here or is this just bad design? ...

Adding Image to a database in Java

I am trying to add an image to a BLOB field in a mysql database. The image is going to be less then 100kb in size. However I am running into problems and was wondering what would be a better way to add this data to the database? com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'Data' at row 1 PreparedStatem...

transaction timeout not working on hibernate with oracle

I am having problem setting the transaction timeout for hibernate on oracle. It does not work.Can anyone help? The "SaveOrUpdate" will not return within the stated 10 seconds. It will hang for a very long time. I am using Oracle 10r2. Hibernate Configuration File oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@9.9.9.9:1521...

How do I write StoredProcedure sub-classes to call Oracle functions?

I've written the following Spring JDBC API StoredProcedure sub-class: class GetLdapPropertiesStoredProcedure extends StoredProcedure { protected GetLdapPropertiesStoredProcedure(JdbcTemplate jdbcTemplate) { super(jdbcTemplate, "get_ldap_properties"); setFunction(true); declareParameter(new SqlReturnResultSet("rs", new Produ...

Best Practice: How to check for a specific java.util.Calendar/Date in SQL.DATE by JDBC?

This is something I struggle with since yesterday. I have appointments to save in a database. They consist of a date and a time, like: 01.02.1970 14:00 (german format, in american I think it would be something like 02/01/1970 2:00pm). First idea: Save it as a SQL.DATE! So i created a table: CREATE TABLE appointments (id NUMBER(10...

How can I retrieve a JDBC ResultSet as an ArrayList?

I'm doing a query to retrieve a large amount of IDs (integers). Instead of iterating millions of times through the ResultSet and copying everything one-by-one to an ArrayList, is there some way to simply retrieve everything as an ArrayList? I understand that ResultSet is supposed to be iterated because the underlying implementation may ...

How to deliver a Java program locally through a browser

Hello, I want to write an application that runs entirely locally on one machine - there is no need for connection to the internet or to any external machines. I was thinking that it would be a good idea to use a web browser as the platform for this application so that I would not have to mess around with lots of UI stuff - I could just...

Encrypted JDBC connection

I do a lot of work on databases over the internet. My company is instituting a policy of not sending any non-encrypted information (including vanilla JDBC). I currently connect to MS Sql Server and db2 databases (both LUW and AS/400). Is there an easy way to encrypt/decript these connections? Edit: Found an interesting and relatively...

Reading Microsoft Access files in Java

How to read (and write) MS Access files (.mdb) in Java? Is there any open-source jdbc driver for MS Access? ...

callablestatement - ArrayIndexOutOfBoundsException

I have a java program that is trying to call a stored procedure that returns a cursor type. However after registering the appropriate out paramaters and calling callableStatement.execute() I recieve an arrayIndexOutOfBoundsException: -1 I dont fully understand why I am recieving this error at this point in the program. Can anyone expl...

When I call PreparedStatement.cancel() in a JDBC application, does it actually kill it in an Oracle database?

Hi All, I have Java JDBC application running against an Oracle 10g Database. I set up a PreparedStatement to execute a query, and then call ps.executeQuery() to run it. Occasionally the query takes a long time, and I need to kill it. I have another thread access that PreparedStatement object, and call cancel() on it. My question is,...