BatchUpdate and MySQL driver
Hi All,
I am using MySQL server and Connector/J driver (an official JDBC driver from MySQL.org).
I am trying to use BatchUpdate operation.
In my batch of operations say, containing 10 operations, if any of the operation fails, all the remaining rows in the batch will be ignored/rejected. There is no way to get the remaining list back. How to handle this kind of situations ?
Thanks in adavance,
Rohit
Omnesys Technologies
I think the problem is not clear to you.
I want perform series of operations (Insert and Update). I want to use Batch Update feature to get better performance. While doing the batch operation, I might get a request (Operation) which fails. This is causing all the remaining requests in the batch to get rejected. I actually want to continue with the remaining operation even if there is an error and from the returned int array I would like to take the action for failed operations.
Is this type of operation possible in Statement ? (On MySQL for PreparedStatement this feature is available but I need it for Statement.)
Thanks a lot,
Rohit
Similar Messages
-
Problem with a j2se program and mysql driver
Hi,
We are developing an application which needs accessing to a mysql database. I have packed the application in a .jar. and inside the jar I have created a folder lib. And inside that folder I have put mysql driver.
As the same way, I have been reading in SDN forum, I have edited manifiest file and I have writen this:
Manifest-Version: 1.0
Sealed: true
Class-Path: lib/mysql-connector-java-5.0.4-bin.jar
Main-Class: package1.Main
When I introduce this command java -jar program1.jar, the jvm says this:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
I know when I use java -jar, classpath system variable doesn't mind. But even this variable is set up properly. If you could help me it would be great. I'm getting stuck with this.
Thanks in advance.@CiMaBuE wrote:
Hi,
We are developing an application which needs accessing to a mysql database. I have packed the application in a .jar. and inside the jar I have created a folder lib. And inside that folder I have put mysql driver.That's the problem. JARs don't look inside themselves for 3rd party JARs. That /lib directory needs to be relative to the program1.jar that you created.
I believe modules or OSGi are supposed to address this, but executable JARs do not today.
% -
I downloaded mySQL and mySQL driver NOW WHAT ?
I downloaded the mySQL and the mySQL driver. What do I do now ?
I saw a book "mySQL and PHP for Dummies" . What is PHP ?
Can you give me direction ?
(without the "go read the archives" type of non-helpful help ?)
Thank you in advance
StanIf it's PHP and MySQL you're interested in, why are you posting to a Java forum?
PHP is a Web scripting language:
http://www.php.net/
If you want to use MySQL with Java, you'll have to learn enough about SQL and relational databases to be able to get into MySQL, create some tables and users, and add some data. Then you'll use the MySQL JDBC driver to let your Java app access those database tables and do CRUD operations on them (Create/Read/Update/Delete).
There's a JDBC tutorial under the Tutorials link to the left on this page.
Here's a Java app that will let you run any valid SQL statement you wish against any database:
import java.sql.*;
import java.util.*;
public class DataConnection
public static final String DEFAULT_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DEFAULT_URL = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\Edu\\Java\\Forum\\DataConnection.mdb";
public static final String DEFAULT_USERNAME = "admin";
public static final String DEFAULT_PASSWORD = "";
/** Database connection */
private Connection connection;
* Driver for the DataConnection
* @param command line arguments
* <ol start='0'>
* <li>SQL query string</li>
* <li>JDBC driver class</li>
* <li>database URL</li>
* <li>username</li>
* <li>password</li>
* </ol>
public static void main(String [] args)
DataConnection db = null;
try
if (args.length > 0)
String sql = args[0];
String driver = ((args.length > 1) ? args[1] : DEFAULT_DRIVER);
String url = ((args.length > 2) ? args[2] : DEFAULT_URL);
String username = ((args.length > 3) ? args[3] : DEFAULT_USERNAME);
String password = ((args.length > 4) ? args[4] : DEFAULT_PASSWORD);
db = new DataConnection(driver, url, username, password);
Object result = db.executeSQL(sql);
System.out.println(result);
else
System.out.println("Usage: db.DataConnection <sql> <driver> <url> <username> <password>");
catch (SQLException e)
System.err.println("SQL error: " + e.getErrorCode());
System.err.println("SQL state: " + e.getSQLState());
e.printStackTrace(System.err);
catch (Exception e)
e.printStackTrace(System.err);
finally
if (db != null)
db.close();
db = null;
* Create a DataConnection
* @throws SQLException if the database connection fails
* @throws ClassNotFoundException if the driver class can't be loaded
public DataConnection() throws SQLException,ClassNotFoundException
this(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
* Create a DataConnection
* @throws SQLException if the database connection fails
* @throws ClassNotFoundException if the driver class can't be loaded
public DataConnection(final String driver,
final String url,
final String username,
final String password)
throws SQLException,ClassNotFoundException
Class.forName(driver);
this.connection = DriverManager.getConnection(url, username, password);
* Clean up the connection
public void close()
try
this.connection.close();
catch (Exception e)
; // do nothing; you've done your best
* Execute ANY SQL statement
* @param SQL statement to execute
* @returns list of row values if a ResultSet is returned,
* OR an altered row count object if not
* @throws SQLException if the query fails
public Object executeSQL(final String sql) throws SQLException
Object returnValue = null;
Statement statement = this.connection.createStatement();
boolean hasResultSet = statement.execute(sql);
if (hasResultSet)
ResultSet rs = statement.getResultSet();
ResultSetMetaData meta = rs.getMetaData();
int numColumns = meta.getColumnCount();
List rows = new ArrayList();
while (rs.next())
Map thisRow = new LinkedHashMap();
for (int i = 1; i <= numColumns; ++i)
String columnName = meta.getColumnName(i);
Object value = rs.getObject(columnName);
thisRow.put(columnName, value);
rows.add(thisRow);
rs.close();
statement.close();
returnValue = rows;
else
int updateCount = statement.getUpdateCount();
returnValue = new Integer(updateCount);
return returnValue;
}Maybe it'll help get you started with Java and JDBC. You're on your own with PHP. - MOD -
Java Web Start and MySQL driver
I am trying to do a simple query on a MySQL database using the JDBC driver from http://www.mysql.com/downloads/api-jdbc-stable.html When I run my app, it works exactly as it should (connects to db, queries, displays in text boxes). When I package it and run it with Java Web Start, it gives the output below on the console. I have set security to all permissions in the jnlp file.
Thanks,
Andy
Java Web Start Console, started Tue Sep 03 14:10:00 CDT 2002
Java 2 Runtime Environment: Version 1.4.0_01 by Sun Microsystems Inc.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at com.sun.jnlp.JNLPClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at SQL.<init>(SQL.java:102)
at SQL.main(SQL.java:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Thread.java:536)Answered my own question....
Before: Class.forName("com.mysql.jdbc.Driver").newInstance();
After: this.getClass().forName("com.mysql.jdbc.Driver").newInstance();
Strange the first worked fine but not for JAWS... -
Can't Find ODBC drivers to link MS Access 2013 and MySQL
Can't Find ODBC drivers to link MS Access 2013 and MySQL.
Is one available?
Thanks,
LarryCould to associate the problem at Office 2013?
I just installed the ODBC Driver; The data source machine was available; When selected I had received the message. When it was selected I had received the message:
"ODBC -- falha na chamada.
[Microsoft][ODBC Driver Manager] O DSN especificado contém uma incompatibilidade de arquiteturas entre o Driver e o Aplicativo (#0)"
In english, could to say: "ODBC -- fail on call.
... The specified DSN contains a architectural incompatibility between Driver and App (#0)"
I don't know yet the reason for this. Anyone knows? -
How to load mysql driver in netbeans 5.0
I configured mysql driver(com.mysql.jdbc.Driver) in netbeans 5.0. but i got this type of errors
(run:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at gdb.gdbop.main(gdbop.java:20))
plz help me for this...............IDEs such as netbeans and eclipse require you to add any external jars to the project's classpath.
for netbeans 5.0, see here:
http://www.netbeans.org/kb/50/using-netbeans/project_setup.html#pgfId-1157099 -
Slow DataBase Access using JDK 1.5 and MySQL
Hi EveryBody,
I am using Jdk1.5 in my project and mysql 5.0 as my database server.
The problem is that, to create a connection for the first time it takes upto 20 to 25 seconds.
when i use the 1.4.2 with the same mysql version it takes only 2 seconds.
In both the cases i am using the JDBC driver (com.mysql.jdbc.Driver )
I cannot understand the problem with the jdk1.5,
so, please help me in resoving this issue.I encountered same problem with connecting Oralce.
It's a bug of JDK1.5.
You need upgrade JDK1.5 to latest version,or use IP address instead of machine name(such as locahost etc.).
Message was edited by:
LucasLee -
Connection issue on 32 bit Linux OBIEE with Postgres and Mysql
I am having trouble running reports on 32 bit Linux OBIEE version 10.1.3.4.0 and 10.1.3.4.1 with Postgres or Mysql as data source . I can connect to same data source (postgres and Mysql) from presentation services on windows box and also run queries from nqcmd using 32 bit linux ODBC driver on linux box running OBIEE server. I turned on odbc trace and I see following failures from Postgres and Mysql.
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 12010] Communication error connecting to remote end point: address = ; port = 9703. (HY000)
SQL Issued: SELECT test_obiee.c1 saw_0 FROM test_Postgre30 ORDER BY saw_0
Mysql odbc trace file :
ppid=1:pid=2908 719a:f4c1fb90 ENTER SQLSetConnectOption
HDBC 0x08d4f170
UWORD 1042
UDWORD 4079342863
ppid=1:pid=2908 719a:f4c1fb90 EXIT SQLSetConnectOption with return code 0 (SQL_SUCCESS)
HDBC 0x08d4f170
UWORD 1042
UDWORD 4079342863
ppid=1:pid=2908 719a:f4c1fb90 ENTER SQLErrorW
HENV 0x00000000
HDBC 0x08d4f170
HSTMT 0x00000000
WCHAR * 0xf4c1e140 (NYI)
SDWORD * 0xf4c1e1a8
WCHAR * 0xf4c1dd40
SWORD 1022
SWORD * 0xf4c1e1ae
ppid=1:pid=2908 719a:f4c1fb90 EXIT SQLErrorW with return code 100 (SQL_NO_DATA_FOUND)
HENV 0x00000000
HDBC 0x08d4f170
HSTMT 0x00000000
WCHAR * 0xf4c1e140 (NYI)
SDWORD * 0xf4c1e1a8
WCHAR * 0xf4c1dd40
SWORD 1022
SWORD * 0xf4c1e1ae
ppid=1:pid=2908 719a:f4c1fb90 ENTER SQLFreeConnect
HDBC 0x08d4f170
ppid=1:pid=2908 719a:f4c1fb90 EXIT SQLFreeConnect with return code 0 (SQL_SUCCESS)
HDBC 0x08d4f170
Postgres odbc trace file :
ppid=1:pid=2951 734f:f4a56b90 ENTER SQLAllocConnect
HENV 0x0a0cf8c8
HDBC * 0x0a12f278
ppid=1:pid=2951 734f:f4a56b90 EXIT SQLAllocConnect with return code 0 (SQL_SUCCESS)
HENV 0x0a0cf8c8
HDBC * 0x0a12f278 ( 0x0a12f398)
ppid=1:pid=2951 734f:f4a56b90 ENTER SQLSetConnectOption
HDBC 0x0a12f398
UWORD 110
UDWORD 0
ppid=1:pid=2951 734f:f4a56b90 EXIT SQLSetConnectOption with return code 0 (SQL_SUCCESS)
HDBC 0x0a12f398
UWORD 110
UDWORD 0
ppid=1:pid=2951 734f:f4a56b90 ENTER SQLSetConnectOption
HDBC 0x0a12f398
UWORD 108
UDWORD 2
ppid=1:pid=2951 734f:f4a56b90 EXIT SQLSetConnectOption with return code 0 (SQL_SUCCESS)
HDBC 0x0a12f398
UWORD 108
UDWORD 2
ppid=1:pid=2951 734f:f4a56b90 ENTER SQLDriverConnectW
HDBC 0x0a12f398
HWND 0x00000000
WCHAR * 0xf31ad2c0 [ -3] "******"
SWORD -3
WCHAR * 0xf31ad2c0
SWORD 6
SWORD * 0xf4a4d9de
UWORD 0 <SQL_DRIVER_NOPROMPT>
I am new to OBIEE and would appreciate any help . I have verified that data source names used in administration matches ODBC DSN in odbc.ini.S Chatterji wrote:
We are in the process of testing backup recovery for our database. We want to test point in time recovery using RMAN.
Issue:
Our production has (64 bit)
Linux DbProd.xxx.dk 2.6.18-164.0.0.0.1.el5xen #1 SMP Thu Sep 3 00:34:43 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
and our test area on VMware has (32 bit)
Linux dbprod.xxx.dk 2.6.18-128.2.1.4.9.el5xen #1 SMP Thu Sep 3 00:34:43 EDT 2009 i686 i686 i386 GNU/Linux
Please advice a best practice to achieve this.
Thanks.
S ChatterjiDuplicate posts do not increase your chances for an answer
Database » Database - Upgrade, - Test recovery on 32 bit Linux where as Production is on 64 bit with Archive
Database » Installation, - Test recovery on 32 bit Linux where as Production is on 64 bit with Archive -
Deploy Applet and MySQL - how to read and write
Question on deploying Applet and MySQL
I am building an applet that is to be a part of a simple game. The applet is supposed to read data from a MySQL server and use it to place towns on the map. In addition, the applet must be able to write to the base.
I have build a prototype and ran it in netbeans on my computer. It then successfully read data from a local MySQL base. HOWEVER; when I embed the applet in html code it no longer reads from the base. My method for connecting to the base is
try{
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
String url=adress;
Connection con=DriverManager.getConnection(url, user, user);
stmt=con.createStatement();
rs=stmt.executeQuery("SELECT * " +
"from "+table+" ORDER BY id");
while(rs.next()){
get data...
Town T=new Town(data...); //construct town object
TL.put(T); //put town objects in an object TownList to use later
con.close();
catch(Exception e){
So;
1) Why wont the applet read anymore?
2) Is there a better way to do this? I have heard that its better to connect applets to servlets in some situations. What demands does this place on the server? Is there software that you need to install on the server to use servlets?I think I do need an applet. The map I have written permits a lot of features that I dont know how to achieve in another way.
1) Zooming in and out on mousewheel
2) Clicking on on two towns gives the distance and by selecting a trooptype one can get information about the traveltime between cities.
3) Right now, I have a feature to find players or groups of players that are of special interest. It allows a player to submit a list of interesting players. The applet reads this list and provides a button with the players name. If one clicks the name of a player, all his cities flash between their originall color and white (using thread).
I need java to do this and I need to run it in a webbrowser because there are som parts of the game that is made up of php. So I assume I have to build it as an applet? -
Listener error with dg4odbc and mysql
Hi all,
First of all, sorry for my English, I'm learning :-)
I'm trying to create a dblink from oracle to mysql, but for now this seems impossible. I have read lots of manuals and post, but no way. I can connect to remote mysql server with "isql my_portal", so, unixodbc and the mysql driver for odbc are working in the server.
The oracle database 10.2 is installed in a Red Hat 64 bits server. Due to hsodbc for 10.2 is only for 32bit i installed the gateway version for 11g without problems (no errors showed, so...) But I have always the same error: "TNS-12541: TNS:no listener dg4odbc" But my configuration seems correct. Can anyone find the error in my config? Thank you
This is the documentation that I have used:
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=561033.1
After apply the modifications to the configuration files, this is what lsnrcntl start says:
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/liste ner.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/srv-bbdd1/listener/alert/lo g.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=1.0.2.42)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=cl-oracle.jferrer.es)(PO RT=1521)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 16-MAR-2011 10:54:38
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/list ener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/srv-bbdd1/listener/alert/ log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=1.0.2.42)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "SQLServerA3" has 1 instance(s).
Instance "SQLServerA3", status UNKNOWN, has 1 handler(s) for this service...
Service "dbjde" has 1 instance(s).
Instance "dbjde", status UNKNOWN, has 1 handler(s) for this service...
Service "my_portal" has 1 instance(s).
Instance "my_portal", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
Then I try tnsping to my_portal:
tnsping:
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 16-MAR-2011 11:36:45
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SID = my_portal)) (HS=OK))
TNS-12541: TNS:no listener
Some information:
- unixodbc driver is in /usr/lib64 (libodbc.so)
- mysql for odbc driver is in /usr/lib64 (libmyodbc.so)
This is my odbc.ini (/etc/odbc.ini):
[ODBC Data Sources]
odbcname = my_portal
[my_portal]
Description = my_portal
Driver = MySQL
SERVER = 1.0.2.98
PORT = 3306
USER = root
PASSWORD = desarrollo
Database = portal_clientes
[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib64/libmyodbc.so
Setup=/usr/lib64/libodbcmyS.so
Added to listener.ora
(SID_DESC =
(SID_NAME = my_portal)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = dg4odbc)
(ENVS = LD_LIBRARY_PATH=/u01/app/oracle/product/10.2.0/db_1/hs/lib:/u01/app/oracle/product/10.2.0/db_1/lib:/usr/lib64)
Added to tnsnames.ora
my_portal =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = localhost)
(PORT = 1521)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = my_portal))
(HS=OK))
initmy_portal.ora
HS_FDS_CONNECT_INFO=my_portal
HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
HS_FDS_TRACE_LEVEL=ON
UseCursorLib=0
set ODBCINI=/etc/odbc.iniThank you for the response. The problem was the solved when change the 1.2.0.40 to 42 :-)
Another issue I saw is your ORACLE_HOME - did you install DG4ODBC in your 10.2 OH?Yes, the documentation said that is certified to work with Oracle 10.2.0.4 that is our version, is this a problem? (¿...?) I had no problem to install dg4odbc with the universal installer.
But I have another problems now. I can't remember the exact error, but my first problem was solved adding this line to initmy_portal.ora:
HS_FDS_QUOTE_IDENTIFIER="'"
Now, when I try to make a select oracle returns this:
ORA-00942: la tabla o vista no existe
[MySQL][ODBC 3.51 Driver][mysqld-5.1.41-3ubuntu12.10]Table 'portal_clientes.CLIENTES' doesn't exist {42S02,NativeErr = 1146}[MySQL][ODBC 3.51 Driver][mysqld-5.1.41-3ubuntu12.10]Table 'portal_clientes.CLIENTES' doesn't exist {42S02,NativeErr = 1146}
ORA-02063: 2 lines precediendo a MY_PORTAL_DBLINK
The table exists, I'm sure, and if I change the query to other tables the result is the same: the table doesn't exist. Any idea?
Thank you for the help -
How to handle blob data with java and mysql and hibernate
Dear all,
I am using java 1.6 and mysql 5.5 and hibernate 3.0 . Some time i use blob data type . Earlier my project's data base was oracle 10g but now i am converting it to Mysql and now i am facing problem to save and fetch blob data to mysql database . Can anybody give me the source code for blob handling with java+Mysql+Hibernate
now my code is :--
==================================================
*.hbm.xml :--
<property name="image" column="IMAGE" type="com.shrisure.server.usertype.BinaryBlobType" insert="true" update="true" lazy="false"/>
===================================================
*.java :--
package com.shrisure.server.usertype;
import java.io.OutputStream;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import oracle.sql.BLOB;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
import org.jboss.resource.adapter.jdbc.WrappedConnection;
import com.google.gwt.user.client.rpc.IsSerializable;
public class BinaryBlobType implements UserType, java.io.Serializable, IsSerializable {
private static final long serialVersionUID = 1111222233331231L;
public int[] sqlTypes() {
return new int[] { Types.BLOB };
public Class returnedClass() {
return byte[].class;
public boolean equals(Object x, Object y) {
return (x == y) || (x != null && y != null && java.util.Arrays.equals((byte[]) x, (byte[]) y));
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
BLOB tempBlob = null;
WrappedConnection wc = null;
try {
if (value != null) {
Connection oracleConnection = st.getConnection();
if (oracleConnection instanceof oracle.jdbc.driver.OracleConnection) {
tempBlob = BLOB.createTemporary(oracleConnection, true, BLOB.DURATION_SESSION);
if (oracleConnection instanceof org.jboss.resource.adapter.jdbc.WrappedConnection) {
InitialContext ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup("java:/DefaultDS");
Connection dsConn = dataSource.getConnection();
wc = (WrappedConnection) dsConn;
// with getUnderlying connection method , cast it to Oracle
// Connection
oracleConnection = wc.getUnderlyingConnection();
tempBlob = BLOB.createTemporary(oracleConnection, true, BLOB.DURATION_SESSION);
tempBlob.open(BLOB.MODE_READWRITE);
OutputStream tempBlobWriter = tempBlob.getBinaryOutputStream();// setBinaryStream(1);
tempBlobWriter.write((byte[]) value);
tempBlobWriter.flush();
tempBlobWriter.close();
tempBlob.close();
st.setBlob(index, tempBlob);
} else {
st.setBlob(index, BLOB.empty_lob());
} catch (Exception exp) {
if (tempBlob != null) {
tempBlob.freeTemporary();
exp.printStackTrace();
st.setBlob(index, BLOB.empty_lob());
// throw new RuntimeException();
} finally {
if (wc != null) {
wc.close();
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
final Blob blob = rs.getBlob(names[0]);
return blob != null ? blob.getBytes(1, (int) blob.length()) : null;
public Object deepCopy(Object value) {
if (value == null)
return null;
byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);
return result;
public boolean isMutable() {
return true;
public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
return assemble(arg0, arg1);
public Serializable disassemble(Object arg0) throws HibernateException {
return disassemble(arg0);
public int hashCode(Object arg0) throws HibernateException {
return hashCode();
public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
return replace(arg0, arg1, arg2);
=================================================================
can anyone give me the source code for this BinaryBlobType.java according to mysql blob handling ..Moderator action: crosspost deleted.
-
Does anyone know of a good link, regarding the setup of a Mysql jdbc driver on a Unix platform. I need to setup a test page and do not know which *.jar file should be referenced in the classpath. Is it a matter of just downloading the [???] jar file or should I make use of connectors?
Thanx in advanceHi,
I have been using MySQL with Java on both windows and Linux for a while now. All I had to do was to
1) Download the mm.mysql-2.0.11-bin.jar file from www.mysql.com
2) Include this JAR file in the classpath.
3) Open a connection to the database using code like this:
String driverClass = "org.gjt.mm.mysql.Driver",
String url = "jdbc:mysql://localhost/databaseName",
String user = "root",
String password = "");
Class.forName(driverClass).newInstance();
Connection connection = DriverManager.getConnection(url, user, password);
This should do the job.
If you are looking for an easy way of reading and writing objects in databases, I suggest you take a look at the Mr. Persister API that we are releasing on monday May 3rd. It is free, and it does all the tedious and boring work of JDBC for you, with only 5% overhead compared to custom JDBC code. Mr. Persister was developed on MySQL, so it will also work with your project. Check it out here:
http://www.jenkov.dk/projects/mrpersister/mrpersister.jsp
Kind Regards,
Jakob Jenkov
www.jenkov.com -
Oracle and MySql via ODBC - Field with special characters
Hi,
I recentely installed and configured DG4ODBC 11.2 in my environment, with Oracle 10g as Database. I have a working ODBC and I can successfully select from tables@mysql.
I have a problem with some fields in the mysql table though: various fields are named "Attività", "Località" and so on. Please, note the "à" character.
Now if I select @mysql from some table with normal field name everything works fine. But in some case I have this error:
[MySQL][ODBC 5.1 Driver][mysqld-5.0.77]Unknown column 'A1.attivit??A commessa'
in 'field list' {42S22,NativeErr = 1054}
The field true name is "attività commessa" and if in a test database I rename the field changing that "à" with a normal "a" everything start working. But of course, that is a production database and I can't change the field name.
Anyone faced that problem before?
My init entry:
HS_FDS_CONNECT_INFO = myodbc5
HS_FDS_TRACE_LEVEL = off
HS_FDS_SHAREABLE_NAME = /usr/lib64/libmyodbc5.so
HS_FDS_SQLLEN_INTERPRETATION=32
HS_FDS_FETCH_ROWS=1
HS_LANGUAGE=ITALIAN_ITALY.I8EBCDIC280
set ODBCINI=/usr/local/etc/odbc.ini
set SQL_MODE='ANSI_QUOTES'
Note: I added HS_LANGUAGE and SQL_MODE but tried even without those entries and it's still not working.
My odbc.ini:
[myodbc5]
Driver = /usr/lib64/libmyodbc5.so
Description = MySQL Driver DSN
SERVER = xxx.xxx.xxx.xxx
PORT = 3306
USER = user
Password = pass
Database = sm_test
OPTION = 3
SOCKET =
CHARSET = latin1
P.S.: Please don't kill me, I'm not the creator of the Mysql database with those field names!I've created your test table in my Oracle database using this extra character and I'm able to describe it properly.
SQL> desc test;
Name Null? Type
ATTIVITÀ VARCHAR2(40)
My character set being used is:
SQL> select * from v$nls_parameters;
NLS_CHARACTERSET
WE8ISO8859P15
NLS_NCHAR_CHARACTERSET
AL16UTF16
NLS_LENGTH_SEMANTICS
BYTE
So as long as it doesn't work for you in your native Oracle database I don't think it would work with DG4ODBC. So yes, it would be best to log a service request so that the Oracle database support can check out the NLS issue.
Edited by: kgronau on Sep 28, 2011 9:21 AM
To be complete here the describe of the MySQL table native and using DG4ODBC:
mysql> create table TEST (attività Varchar(40));
Query OK, 0 rows affected (0.00 sec)
mysql> desc TEST;
---------------------------------------------------+
| Field | Type | Null | Key | Default | Extra |
---------------------------------------------------+
| attività | varchar(40) | YES | | NULL | |
---------------------------------------------------+
1 row in set (0.00 sec)
SQL*Plus: Release 11.2.0.2.0 Production on Wed Sep 28 09:20:17 2011
SQL> desc "gateway"."TEST"@MYSQL_DG4ODBC_EMGTW_1122_DB;
Name Null? Type
attività VARCHAR2(80)
So in general it should work. -
Strange behaviour of jdbc-mysql driver
I am trying to store japanese characters in mysql and display also after reading from the database using JSP. I am using the following code.
<%@ page contentType="text/html; charset=UTF-8"%>
....... some code ......
<%
Class.forName( "org.gjt.mm.mysql.Driver" );
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DB?useUnicode=true&characterEncoding=UTF-8", "user", "pass" );
Statement st = con.createStatement();
st.executeUpdate( "insert into test values('" + request.getParameter( "imgname" ) + "')" );
ResultSet rs = st.executeQuery( "select * from test" );
while( rs.next() ) {
%> DB Value: <%= rs.getString( "imgname" ) %>
<% } %>
I found one strange behaviour. I have to change the DriverManger.getConnection line to the following, to write the data correctly in the database.
DriverManager.getConnection("jdbc:mysql://localhost:3306/DB","user","pass")
If I read from the database using the same parameters as above, I am getting garbled data.
To retrieve the data correctly from the database I have to use the following line instead of the previous one.
DriverManager.getConnection("jdbc:mysql://localhost:3306/DB?useUnicode=true&characterEncoding=UTF-8", "user", "pass" );
In short, I have to pass different parameters to DriverManager.getConnection() for writing and reading from the database. But it is not possible practically. I am using mm.mysql-2.0.8 jdbc-mysql driver, mysql is 3.23.47 and english windows 2000.
I have tried the string.getBytes("UTF-8") and new String( getBytes(string), "UTF-8") methods, but not getting the correct data.
Can anybody guide me how can I store and display the japanese character correctly?
Thanks to all,
gaurang.I downloaded the latese driver from sourceforge, but still the same thing is happening. Is there any other thing which I should do?
Thanks
gaurang. -
How to import MySQL Driver in Jbuilder
I am creating a GUI application using swing with the help of JBuilder. I have used MySQL as Database. For connection it to java I've used MySQL J-Connector Driver. But I am not being able to import that driver(classes) in jbuilder.
When i run the application at the cmd prompt it works fine (got connected), but when i try to run it under jbuilder it gives error like
java.com.mysql.Driver class not found.
I think it is classpath problem
Please help me, setting this problemNo, you need not import class as you give qualified
class name in Class.forName(). Better post your code
here. Somebody will help you out.Below is the code of CLASS CreateConnection, I'm using to create connection to MySQL. I instantiate this class and use the connection. This class is being called when a connection to database is required. I am creating a desktop application using swing.
package project1;
import java.sql.*;
public class CreateConnection {
private String host,database,username,password;
String db_string;
Connection conn;
Statement smt;
ResultSet rs;
//Parameterized constructor
CreateConnection(String host, String database, String username, String password){
this.host=host;
this.database=database;
this.username=username;
this.password=password;
db_string="jdbc:mysql://"+host+"/"+database+"?user="+username+"&password="+password ;
create();
//Parameterized constructor 2
CreateConnection(String db_string){
this.db_string=db_string;
create();
public void create(){
System.out.println("using: " +db_string);
try{
System.out.println("Loading drivers........");
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Driver loaded !");
conn = DriverManager.getConnection(db_string);
smt = conn.createStatement();
System.out.println("testing database .........");
smt.execute("create table test(no varchar(22))");
catch(Exception e){
System.out.println(e);
System.exit(0);
System.out.println("Successfull");
public ResultSet execute_q(String query){
try{
System.out.println("Executing "+query);
rs=smt.executeQuery(query);
catch(SQLException sqle){
System.out.println("Execption thrown" +sqle);
return null;
return rs;
}
Maybe you are looking for
-
Another "Flash.ocx missing" VISTA 64-Bit syswow64
The exact error message is: This program requires flash.ocx, which is no longer included in this version of windows. I know this has been answered numerous times, but, and I stress, BUT, not for users running 64 Bit. The copy, paste and rename to fl
-
I have iTunes 11.1.3 and when I click on iTunes Store in the top right corner I just get a blank screen. Please help me! I want to buy music!
-
Boot: cannot open kernel/unix
Hi ebody! I have installed a Sol2.5.1 to a new ULTRA5 external SCSI hard drive. The installation was successfull. I have set the boot device to external hard drive and started the booting. I have got a message "boot: cannot open kernel/unix" ! All ke
-
HR: PC00_M37_TRM0
I need to run a FORM in PC00_M37_TRM0 transaction. How do I configure this application to run it? tks, Marcos Ferreira
-
Flash Player 12 won't work for me
I downloaded Adobe Flash Player 12 from Adobe site. I have IE and Windows 7 Premium. Computer tells me Flash Object is installed and it is enabled. It won't work for me. Adobe help page says it is either not installed or enabled, but my computer s