jdbc

JUnit Servlets testing with jndi lookup for the datasource

How to make unit test of servlets which uses jndi for lookup of datasource (JDBC) ? ...

Connection problem in Win2k3 server 64 bit with JDBC

DriverManager#getConnection() returns null when I am deploying my JSP/Servlet package in a Windows 2003 Server environment (64 bit). The database is Microsoft SQL 2005 Enterprise Edition. The code is: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:calsoft2k","xxx","xxx"); The same code is ...

How do I get SQL LOAD DATA from CSV to honour the column type when loading?

I am loading a CSV file into MySQL (5.1) using CREATE TABLE and LOAD DATA. I have a number of columns which are textual types (categories) but contain numerical values. When I create the table I assign these columns as VARCHAR(254) but the JDBC driver throws a SQLException "Data truncated for column AgeGroup at row 1". My data looks l...

problem generating random no in java

i have written a code like this but it is giving exceptions.actually i want to generate a random value.save into the database and return the same to the user import java.math.BigInteger; import java.security.SecureRandom; public static String recoverpassword(String uid,String ans) { try { verifyans.setString(1,uid); ...

Problem with Informix JDBC, MONEY and decimal separator in string literals

I have problem with JDBC application that uses MONEY data type. When I insert into MONEY column: insert into _money_test (amt) values ('123.45') I got exception: Character to numeric conversion error The same SQL works from native Windows application using ODBC driver. I live in Poland and have Polish locale and in my country comma...

Defending against a 'WAITFOR DELAY' sql injection attack?

Hi all, The problem We need to defend against a 'WAITFOR DELAY' sql injection attack in our java application. Background [This is long. Skip to 'Solution?' section below if you're in a rush ] Our application mostly uses prepared statements and callable statements (stored procedures) in accessing the database. In a few places we dy...

integrate ms access and mysql in java

Hi, I have a problem connecting to MS Access and MySQL using Java. My problem is that I cannot find the driver for MySQL. Here is my code: <%@ page import="java.sql.*" %> <% Connection odbcconn = null; Connection jdbcconn = null; PreparedStatement readsms = null; PreparedStatement updsms = null; ResultSet rsread = nul...

Using DB Api in a portable manner

Hi, I need to develop some kind of application and use DB in it. Let's say i want to develop it over Windows currently, however, in a couple months i may have to migrate it to Linux. I started reading a little bit about it, but couldn't get to point i needed. Is there or isn't a generic/protable/standart api for using DB ? I read th...

Building a jar with MySQL jdbc on solaris

Hi All, Im building a java application that uses JDBC to connect to MySQL. I have an ant script that compiles my code and then packages it, along with log4j, junit, libshout-java and the mysql jdbc driver into one executable jar. This all works fine on ubuntu 9.10, and my code connects to mysql and away we go. However my production env...

How to quote/escape identifiers such as column names with JDBC?

Different database servers use different ways to quote and escape identifiers. E.g. "foo bar" vs `foo bar` vs [foo bar], or "10""" vs "10\"", or identifiers such as FooBar or array need to be quoted for some databases but not for others. Is there any API method that performs the quoting/escaping correctly for a given database connectio...

JDBC use urls to connect

When you setup a URL in your jdbc properties like: jdbc:derby://localhost:1527/vehicle;create=true Does this mean all the data is being sent via HTTP on a specific port? (it seems so obviously) ...

Read a large result set in chunks from mysql

I am trying to read a huge result set from mysql. Reading them in a straight-forward manner didn't work, as mysql tries to return all results together, which times out. I found the following piece of code which tells mysql to read the results back one at a time: stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql...

DB Connection pool in Servlet or Listener?

Hi, I'm thinking of using DB Connection Pool in J2EE. Database: MySQL Servlets: http://www.webdevelopersjournal.com/columns/connection_pool.html Listeners: http://onjava.com/onjava/2006/04/19/database-connection-pooling-with-tomcat.html now which is a better option & why? Also, any working source code will help me save time. Warm Re...

How to sanitize log messages in Log4j to save them in database

Hello, I'm trying to save log messages to a central database. In order to do this, I configured the following Appender in log4j's xml configuration: <appender name="DB" class="org.apache.log4j.jdbc.JDBCAppender"> <param name="URL" value="jdbc:postgresql://localhost/logging_test" /> <param name="user" value="test...

I got error named no suitable driver?

I couldn't find out why it shows error. I have created table named books in Oracle priorly. create table books(num number); Then I wrote code in Java: Class.forName("oracle.jdbc.driver.OracleDriver"); con=DriverManager.getConnection( "jdbc:oracle:thin:@CF:1521:orcl", "scott", "tiger"); Statement s=con.createStatement(); s...

sql delete lock

I execute a query in JDBC delete * from mytable where ... I got: java.sql.SQLException: The total number of locks exceeds the lock table size I have about 200k records in the table. how to fix this? ...

JDBC driver for Oracle 10G XE

Hello, I have installed Oracle 10G XE. I want to connect to it using JDBC . Which driver should i use for it and from where can i download it ? Thank You. ...

Conversion strategies for bind variables

A Spring JDBC question: I use a lot of objects as bind variables which are not automatically mapped to their JDBC equivalents, e.g. jdbctemplate.query(sql, foo, bar, wee) with foo, bar and wee being instances of objects which are not covered by the JDBC type autoconversion. Can anyone on SO suggest a best practice for a conversion strat...

Eclipse JPA project - defining connection to Oracle RAC

Recently I wanted to play a bit with Eclipse and JPA. Thus I wanted to create a JPA project. I got stuck when specifying the database connection, as editing the "Connection URL" (shown on the image) is not possible and I want to enter a (good, working) connection string to an Oracle RAC server which looks more or less like that: jdbc:...

JDBC always tests the last row of MySQL table?

Hi, I have a Manager class that saves data in the SQL table and also get result from SQL table and test these data.when I run my program,one frame will be shown that gets ID and password and if they are correct ,the other frame will be shown.BUT I don't know that why it just test the last row of SQL table?? i mean if I set those text fie...