jdbc

dbcp: number of open prepared statement

Hi, I get MaxOpenPreparedStatement exception in my program. I can monitor number of objects in GenericObjectPool with getNumActive()/getNumIdle() functions. How can I get connection & prepared statement pools from org.apache.commons.dbcp.BasicDataSource object? Thanks ...

In JDBC, when autocommit is false and no explicit savepoints have been set, is it good style or a waste to rollback?

Say you have the following code: Connection conn; try { conn = ... // get connection conn.setAutoCommit(false); ... // Do some modification queries and logic conn.commit() } catch(SQLException e) { conn.rollback() // Do we need this? conn.close() } In this code, if there is an exception, is it better style to jus...

Inserting multiple rows using JdbcTemplate

How can I execute the following SQL in a scalable way using JdbcTemplate running on mySQL. In this case, scalable means: Only one SQL statement is executed on the server it works for any number of rows. Here's the statement: INSERT INTO myTable (foo, bar) VALUES ("asdf", "asdf"), ("qwer", "qwer") Assume that I have a list of POJO'...

Programatically setting the db url/user/password in Hibernate

I need to centralize all settings for our Java web application in one .properties file. I can still have hibernate.cfg.xml for adding mappings to entity classes but I need to keep all of our settings for the database and custom paths in one .properties file. Originally I kept my configs in hibernate.cfg.xml as follows.... <?xml vers...

Is it possible to create an object for an interface type

Connection con = DriverManager.getConnection("jdbc:odbc:MyDataSource1"); This is a JDBC programing line. In this line, we are creating an object for Connection interface. How it is possible? ...

Force MySQL 4.1 return to Decimal type

I'm using JDBC to access a MySQL 4.1 database and have problems with queries of Decimal type. When I do a query on a single Decimal column (i.e., SELECT amount AS v FROM Customer) I get a BigDecimal through the JDBC driver, but when I do an an operation of Decimal columns (i.e., SELECT amount + tax AS v FROM Customer) I get a Double eve...

oracle jdbc jface wizardpage

I want to create a jface wizard and collect credentials as I go along - password and username on page 1 and then on page 2 I want to display a list I get from an oracle database. I am using eclipse, and have all the controls in the places I want. On page 2 I put the oracle connection details and sql statement in the createControl method...

how to install JDBC and how to use it to connect to mysql?

Hey all i am trying to install JDBC but i dont know how, when you only have the jar file, i copied it to my java ext folder but it keep giving me an error, can anyone show me how to complete install the driver and use it? below is the codes that i used import java.sql.*; public class Test1 { public static void main (Stri...

Getting a Connection with DBCP via the Sybase Jconnect JDBC driver

I am trying to get a Connection in the following code and I keep getting an SQLException with the message "Login failed" and with the details "Specified database not found". Connection con = null; BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.sybase.jdbc.SybDriver"); dataSource.setUsername("u...

Java MYSQL Connection hangs in Windows 7, Works on Mac

The same programs work on the Mac but does not seem to work on Windows. I have tried using both hibernate and a regular mysql.connection but both seem to hang. My firewalls are all off and I have no problem connecting to the database through 3rd party programs like sqlyog or even through the HQL query generator in netbeans. But when it ...

Is possible to do proxy authentication using SQL Server JDBC driver?

Oracle JDBC driver provides option to do proxy authentication for multi-tier architecture design. Are there any similar/equivalent option available with SQL Server JDBC driver? ...

org.apache.commons.dbcp.DelegatingPreparedStatement is closed

org.apache.commons.dbcp.DelegatingPreparedStatement is closed Could i know in which situations this exception will come. I closed all result sets and prepared statements. How can i solve this problem. Code : public int UpdateMovementLines(List<MaterialRequestIssuanceVO> mlinelist,String projId,String documentno,String user){ ...

How do I place large (or at least nontrivial) BLOBs into Oracle with JDBC?

I'm working on an application to do some batch processing, and want to store the input and output data as files in BLOB fields in an Oracle database. The Oracle version is 10g r2. Using the PreparedStatement.setBinaryStream() method as below will insert a small text file into the database, but I'm not having any luck with a larger image...

Connecting Java Applet to MySQL DB - Communications link failure

I am trying to connect my Java Applet to a MySQL Database. I know that it works, because I can connect to it on localhost and it retreives a list of records just fine. But when I put it on the internet, it doesn't work. Here is my applet: http://mystikrpg.com/play It's signed, but I keep getting the following exception: SQLExceptio...

jsp coding problem

I am a programmer, new to jsp, trying to write some code. i have written like <% int i=1; String connectionURL = "jdbc:mysql://localhost:3306/registration"; Connection connection = null; Statement stmt = null; ResultSet rset = null; Statement stmt1 = null; ResultSet rset1 = nu...

How to set a role in DataSource from Spring

Hi, I have to use a default Role so that after the datasource has been defined and connected that role will allow me to use select statements. I know its little weird but I have to do it due to security concerns. So here is the code in my Spring's applicationContext.xml: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSou...

Prepared Statements and JDBC Drivers

Hi, I have the below questions on Prepared Statements in Java. Is it beneficial to use Prepared Statements when the SQL Query does not have any Where clause ? Assume a simple query Select * from tablename; It is said that the Prepared Statement is compiled once and only the values are substituted the second time. Hence it is faster as...

What is the right way to use JDBC transactions in Java?

I'm using this template: try { connection.setAutoCommit(false); try { // ... do something with that connection ... connection.commit(); catch (SQLException exception) { connection.rollback(); throw exception; } finally { connection.setAutoCommit(true); } } catch (SQLException ...

jdbc programming through oracle

what is the service name of oracle10g xe database ...

Data source rejected establishment of connection, message from server: "Too many connections"

Hi folks, I am trying to make connections to my database using connection pooling library: DBPool. Here's my source code. DBUtils.java /** * */ package DB; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.sql.ConnectionPoolDataSource; import snaq.db.ConnectionPool; import c...