jdbc

create and insert values using mysql JDBC

Hi all, I have the sample code. public void UpdateTable1() { for (int t = 0; t < 20; t++) { if (consumer == 1 && number == 1 && provider1 == 31 && feedback == 1) { try { Class.forName(driverName); con = DriverManager.getConnection(url + dbName, "root", "mysql"); t...

JDBC get/setObject vs. get/setSpecificType

JDBC ResultSet offers getObject, getInt, getString etc. methods, and PreparedStatement has analogous setters. Apart from type compile-time type safety, do the type specific getters/setters have any (dis)advantages, or is it OK to use getObject/setObject everywhere? ...

Java SQL database independence.

Hello, I have been looking for an alternative to Hibernate for various reasons. I came across Liquibase and i like the idea so i am willing to try it. Liquibase will cater for database creation/modification in a SQL independent fashion. My main question is how does my code in my application execute SQL statements without being database ...

Problem with SQL, ResultSet in java

How can I iterate ResultSet ? I've tried with the following code, but i get the error java.sql.SQLException: Illegal operation on empty result set. while ( !rs.isLast()) { rs.next(); int id = rs.getInt("person_id"); SQL.getInstance().getSt().execute("INSERT ref_person_pub(person_id) VALUES(" + id + ")"); } Update: I've...

SQLServer Binary Data with ActiveRecord and JDBC

I'm using the activerecord-jdbc-adapter with ActiveRecord to be able to access a SQLServer database for Rails Application running under jRuby and am having trouble inserting binary data. The Exception I am getting is below. Note I just have a blurb for the binary data from the fixtures that was working fine for MySQL. ActiveRecord::Stat...

Auto Reconnect of Database Connection

I have a DBCP connection pool in Tomcat. The problem is that when the connection is lost briefly the appliction is broken because DBCP won't try to reconnect again later when there is a connection. Can I get DBCP to reconnect automatically? ...

Getting a ResultSet/RefCursor over a database link

From the answers to http://stackoverflow.com/questions/1122175/calling-a-stored-proc-over-a-dblink it seems that it is not possible to call a stored procedure and get the ResultSet/RefCursor back if you are making the SP call across a remote DB link. We are also using Oracle 10g. We can successfully get single value results across the l...

How to connect to MS Access 2007, from Java on a mac

I'm looking for a way to connect to a MS Access 2007 database from Java. I don't believe the ODBC way is available to me as I'm writing on a mac and will be pushing this product to Linux. The HXTT drivers also do not work with 2007. Is there a way, a tutorial, an example, etc that accomplishes this? Setting the connection as a JNDI Data...

How to detect SQL Server stored procedure failure from JDBC client?

I have some Java code that uses JDBC to execute a "CREATE PROCEDURE" statement on a SQL Server 2008 instance. The create proc is failing due to an error ("Implicit conversion from data type xml to varchar(max) is not allowed. Use the CONVERT function to run this query."). This error is not being raised to the JDBC client and so I have n...

Improve mysql JDBC insert call

i have a legacy Java system that every time it gets an order it makes a JDBC call to a stored procedure for each field in the order. Generally the stored procedure will get called 20 to 30 times for each order. The store procedure is just doing an insert into a table for each field. i need to improve the performance of this operat...

Oracle doesn't remove cursors after closing result set

Note: we reuse single connection. ************************************************ public Connection connection() {                try {            if ((connection == null) || (connection.isClosed()))            {               if (connection!=null) log.severe("Connection was closed !");                connection = DriverManager.getConn...

Hibernate or JPA or JDBC or ???

I am developing a Java Desktop Application but have some confusions in choosing a technology for my persistence layer. Till now, I have been using JDBC for DB operations. Now, Recently I learnt Hibernate and JPA but still I am a novice on these technologies. Now my question is What to use for my Java Desktop Application from the fol...

ResultSet and aggregation

Ok, I admit my situation is special There is a data system that supports SQL-92 and JDBC interface However the SQL requets are pretty expensive, and in my application I need to retreive the same data multiple times and aggregate it ("group by") on different fields to show different dimensions of the same data. For example on one scree...

Avoiding CheckStyle magic number errors in JDBC queries.

Hello, I am working on a group project for class and we are trying out CheckStyle. I am fairly comfortable with Java but have never touched JDBC or done any database work before this. I was wondering if there is an elegant way to avoid magic number errors in preparedStatement calls, consider: preparedStatement = connect.prepar...

How to get equivalent of ResultSetMetaData without ResultSet

I need to resolve a bunch of column names to column indexes (so as to use some of the nice ResultSetMetaData methods). However, the only way that I know how to get a ResultSetMetaData object is by calling getMetaData() on some ResultSet. The problem I have with that is that grabbing a ResultSet takes up uneccesary resources in my mind -...

using Spring JdbcTemplate for multiple database operations

I like the apparent simplicity of JdbcTemplate but am a little confused as to how it works. It appears that each operation (query() or update()) fetches a connection from a datasource and closes it. Beautiful, but how do you perform multiple SQL queries within the same connection? I might want to perform multiple operations in sequen...

Spring's JdbcDaoSupport (using MySQL Connector/J) fails after executing sql that adds FK

I am using Spring's JdbcDaoSupport class with a DriverManagerDataSource using the MySQL Connector/J 5.0 driver (driverClassName=com.mysql.jdbc.driver). allowMultiQueries is set to true in the url. My application is an in-house tool we recently developed that executes sql scripts in a directory one-by-one (allows us to re-create our sche...

Problems with Date, preparedStatement, JDBC and PostgreSQL

I Have to get a movie from a PostgreSQL database that matches a given title and release date. title is a character(75) and releaseDate is a date. I Have this code: String query = "SELECT * FROM \"Movie\" WHERE title = ? AND \"releaseDate\" = ?)"; Connection conn = connectionManager.getConnection(); PreparedStatement stmt = conn.prepareS...

JDBC ODBC.. (Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException)

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { PreparedStatement p1; try { System.out.println("works"); String s1="insert into reg(num,name) values(?,?)"; p1 = conn.prepareStatement(s1); System.out.println("Works"); JOptionPane.showMessa...

How to pass SQLXML type to view in Spring MVC?

In my webapp controller I'm getting results from the db, which are of type java.sql.SQLXML. I want to pass it to the view to be returned verbatim (as XML). The problem is, the data associated with SQLXML is released as soon as I leave JdbcTemplate call. How then should I pass the data to the view using a model? ...