Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all 884 articles
Browse latest View live

New Java Open Source project for comparing MySQL tables (no replies)

$
0
0
www.diffkit.org

Open Source
java
high quality with lots of unit and regression tests
full support for MySQL
allows you to diff (compare) tables

JDBC Default charset (no replies)

$
0
0
Hi, I would like to know what's the best way to make the JDBC driver work with UTF8 strings as needed?

When I do:
pStmt.setString(1, myString);
it doesn't insert correct unicode characters in db (the charset and collation are correct there)

I have to use this:
pStmt.setBytes(1, myString.getBytes("utf8"));

and that's inconvenient, is there any parameters for JDBC URL, or some settings in connection, etc, to make setString work normally with UTF8 strings?

group by being ignored (no replies)

$
0
0
Hello,

I'm using the mysql java connector version 5.1.13. I have this basic sql query.

select tag, count(tag) as num from tags group by tag order by num

The query executes but the results that come back are is if the group by clause was completely ignored? When I take the same query and run it from the mysql command line or phpmyadmin, it works fine.

Regards,
Brian

Empty Result Set returned from call to getSchemaNames() (no replies)

$
0
0
HI Guys ,
I was trying to retrieve the names of all databases(schemas... whatever you like to call them ) . The JDBC Metadata API came up with .getSchemaNames() . Its working fine on other databases ... but when I made the same call to My Sql , its returning an empty result set . I am using MySQl Connector ODBC 5.1.4 .

Connector/J + JNA + Unix Sockets (Works, But Need Help w/Performance) (no replies)

$
0
0
Hi Everyone --

In attempt to get better performance in an environment where a Java application is deployed to the same Linux server where MySQL is running, I've written a SocketFactory implementation that uses Unix Sockets:

http://www.productivity.org/projects/mysqlunixsocket/

This is an analog to using the NamedPipeSocketFactory on Windows systems. To pull this off, I use the JNA (Java Native Access) library in order to get to the underlying C library's socket methods (socket, connect, read, write, and close).

The code works, but does not perform better than TCP/IP as I expected.

I noticed a dramatic improvement by wrapping my underlying InputStream and OutputStream instances with BufferedInputStream and BufferedOutputStream (respectively), but it's still worse than TCP/IP by 20% or more.

I'm looking for assistance to tune this code such that I can consistently get results better than TCP/IP. I've seen dramatic improvements in speed in Perl code using MySQL's socket connectivity vs. TCP/IP, and that served as inspiration.

Also -- if anyone is of the opinion that this isn't worth the effort, I'd like to know why.

Thanks in advance!

-- Justin

Connection to mysql database with .NET C# (1 reply)

$
0
0
Hi, I have tried for a long time now to get a connection to mysql database.
I am using Visual Studio 2008 with .NET and C#.
I have included my database on the server explorer and all apropriate tables are included but when I view the code in the browser it appears blank!
This is my connection code held in default.aspx.cs:

using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace trybuyconnect
{

public class Tutorial4
{
public static void Main()
{
string connStr = "server=localhost; id=root; database=database_name; password=******;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();

string sql = "SELECT * FROM product_list";
MySqlCommand cmd = new MySqlCommand(sql, conn);
object result = cmd.ExecuteScalar();
if (result != null)
{
int r = Convert.ToInt32(result);
Console.WriteLine("Products: " + r);
}

}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

conn.Close();
Console.WriteLine("Done.");
}
}
}

Does anyone know if there is a problem with the connection code.
Also, I havn't added any code to default.aspx, should I be adding code to that file?

Any suggestions?

Thanks

David

Strange hack in TimeUtils.changeTimezone (no replies)

$
0
0
I have a mysql server which I would like to connect to from two locations in different timezones. For this I tried to use useTimezone=true & serverTimezone=GMT parameters for the connection but I stumbled upon a very strange hack in changeTimezone.

After computing the offsetDifference the code does what seems like a hack:

if (rollForward || (conn.isServerTzUTC() && !conn.isClientTzUTC())) {
toTime += offsetDiff;
} else {
toTime -= offsetDiff;
}

where rollForward is false

So if the time zone of the server or of the client is UTC then the difference is added otherwise is substracted ???

So if I am in GMT+2 the time set on the server will be GMT + 4

But if I set serverTimezone=CET (i.e. GMT+1), then the time is set correctly to GMT + 1

What is the purpose of this hack and what would be the workaround?

Database with web extension (no replies)

$
0
0
Hey. I'm new to SQL and I've got Apache/Jakarta Tomcat 5.5 and Eclipse Helios (3.6). I'm trying to setup what is essentially a functioning online bookstore like amazon.com (though business practices such as secure connections for transactions are not to be implemented at this time) using JSP. For some reason it keeps giving me "no appropriate drivers" messages when I'm trying to connect to my database. This is a major snag as I can't do any testing/coding whatsoever until this is fixed. Can anybody explain why I'm having this problem and/or how to fix it?

com.mysql.jdbc.Driver
No suitable driver found for URL
null

EDIT: problem solved, solution: download Connector/J (file mysql-connector-java-5.1.13.jar) and move it into the Java Runtime Environment lib\ext directory (mine, for example, is at C:\Program Files\Java\jre6\lib\ext\) and and the location to the CLASSPATH environment variable.

question regarding 20.3.5.1.1. Connecting to MySQL Using the DriverManager Interface (1 reply)

$
0
0
Hello, this is for the line
"conn = DriverManager.getConnection("jdbc:mysql://localhost/rootkit"+" user=root&password=1231");".
I got an exception that says "SQLException: No suitable driver found for jdbc:mysql://localhost/rootkit user=root&password=1231"
what does it really mean? also, what exactly is database driver?
i've been googling it but nothing seems to really answer my question.
im quite new to the database world so any help would be appreciated :)

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' (1 reply)

$
0
0
Hi all

I am working on a web based project using spring ,hybernate +jpa .I am trying to configure JTA Transactions with Atomkios
my backend is mySql. I am not able to setup the application to work with mySql.
my web server is tomcat 5.5.I am trying to cal jndi configured datasource .. here my code is
persistence.xml is
<persistence-unit name="exhub" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/exampleWeb</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<class>com.evolvus.common.model.Talogin</class>
<class>com.evolvus.common.model.TaUser</class>
-----------------
-----------------
<properties>
<property name="hibernate.transaction.manager_lookup_class"
value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
</ properties>
</persistence-unit>
</persistence>

and my orm.xml is

<description>Evolvus Solutions</description>
<package>com.evolvus.common.model</package>


<entity class="com.evolvus.common.model.TaUser" name="TaUser">
<table name="ta_user" />
<attributes>
<id name="userId">
<column name="USER_ID"/>
<generated-value strategy="TABLE" />
</id>
<basic name="userName">
<column name="USER_NAME" length="50" />
</basic>

</attributes>
</entity>
---------------
--------------
---------------

</entity-mappings>
and also my config.xml is

<beans: bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<beans: property name="useTransactionAwareDataSource"
value="true" />
<beans: property name="hibernateProperties">
<beans: props>
<beans: prop key="hibernate.dialect">${database.target}</beans:prop>
<beans: prop key="hibernate.connection.isolation">3</beans:prop>
<beans: prop key="hibernate.current_session_context_class">jta</beans:prop>
<beans: prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
</beans: prop>
<beans: prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
</beans: prop>
<beans: prop key="hibernate.connection.release_mode">on_close</beans: prop>
<beans: prop key="hibernate.show_sql">false</beans: prop>
</beans: props>
</beans: property>
</beans: bean>

<beans: bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
<beans: property name="entityManagerFactory">
<beans: ref bean="entityManagerFactory" />
</beans: property>
</beans: bean>
<beans: bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<beans: property name="persistenceUnitName" value="payhub" />
<beans: property name="jpaVendorAdapter">
<beans:bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<beans: property name="generateDdl" value="false" />
<beans: property name="showSql" value="true" />
<beans: property name="databasePlatform" value="${database.target}" />
</beans: bean>
</beans: property>
<beans: property name="persistenceXmlLocation">
<beans: value>classpath:META-INF/persistence.xml</beans:value>
</beans: property>
</beans: bean>
</beans: beans>
and i configured jndi in tomcat 5.5

my Apache Software Foundation\Tomcat 5.5\conf.xml

<Resource
name="jdbc/exampleWeb"
type="javax.sql.DataSource"
maxActive="4"
maxIdle="2"
username="root"
maxWait="5000"
validationQuery="SELECT=1"
driverClassName="com.mysql.jdbc.Driver"
password="roopt"
url="jdbc\:mysql\://localhost\:3306/welcomeHub"/>

and my application\web.xml

<resource-ref>
<description>PaymentsDatabase</description>
<res-ref-name>jdbc/exampleWeb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

My server is staring fine but when i trying to access db data i am getting the following error in my web browser

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)



Help me

pls help me with this error (2 replies)

$
0
0
Im building an chat system in java and i use jdbc mysql connector to connect
my users table in the mysql.
i want every one to use my chat system so i use wamp for it (so peaople can access to the table)

here is my MakeCon() function :

Connection con = null;
String url = "jdbc:mysql://84.111.249.5/";
String dbName = "mytables";
String driver = "com.mysql.jdbc.Driver";
String userName = "xxx";
String password = "xxx";
try
{
Class.forName(driver).newInstance();
}
catch (InstantiationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
con = DriverManager.getConnection(url+dbName,userName,password);


as u can see i typed every thing right.
and all is working right even i type my ip address it shows my site and i can do all privelges from the db .

but from java i just cannot connect because this error message i get and i dont know what to do to fix that i google it and try everything here is the error message i get from java :
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai
lure

The last packet sent successfully to the server was 0 milliseconds ago. The driv
er has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ChatSystem.makeCon(ChatSystem.java:1202)
at ChatSystem.actionPerformed(ChatSystem.java:1549)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at com.jtattoo.plaf.BaseButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
... 41 more

JDBC/JNDI config (5 replies)

$
0
0
Hi All.

I was connecting to my database via a JDBC URL Connection String but I have since set up JNDI with Apache Tomcat 6.0.29.

I am wondering how I configure the parameters, "loadBalanceStrategy" etc through JNDI because previously I was doing it like this in my JSP:

Properties props = new Properties();
props.put("user", "username");
props.put("password", "secret");
props.put("loadBalanceStrategy", "bestResponseTime");
conn = DriverManager.getConnection("jdbc:mysql:loadbalance://ip:3306,ip:3306/DBName", props);

But obviously now with JNDI I just have the following:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/DBName");
Connection c = ds.getConnection();

So I am not sure if I need to set up loadBalanceStrategy in the JSP or in some XML file within ApacheTomcat or what...

I would appreciate any help.
Thanks

Having some issues connecting (1 reply)

$
0
0
I downloaded the JDBC connector for connecting to Mysql from Java,

How every my connection code is as follows:

public void testConnection()
{
try
{
//Create a new instance of the JDBC driver
Class.forName("com.mysql.jdbc.Driver").newInstance();
//Attempt to connect to the "balan_well" database
conn = DriverManager.getConnection("jdbc:mysql:///balan_well", "root", "2474776");
//Check to see if the connection has closed
if(!conn.isClosed())
{
//If it hasn't, then print that the connection was successful
System.out.println(" CONNECTED to mySQL server using TCP/IP");
}
}
catch (InstantiationException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
}

While I get the following errors:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at binConverter.MySQLConnection.testConnection(MySQLConnection.java:62)
at binConverter.AppDriver.useConverters(AppDriver.java:57)
at binConverter.AppDriver.main(AppDriver.java:29)
[ INSERTING DATA INTO WELL TABLE... ]
Exception in thread "main" java.lang.NullPointerException
at binConverter.MySQLConnection.loadWellTable(MySQLConnection.java:101)
at binConverter.AppDriver.useConverters(AppDriver.java:60)
at binConverter.AppDriver.main(AppDriver.java:29)

The connection Jar I am using is: mysql-connector-java-5.1.13.jar

'0.0' in column '82' is outside valid range for the datatype FLOAT. (1 reply)

$
0
0
Hi All,
We have a Spring batch job which runs through all the accounts and adjusts the balances. We are getting the following exception in this batch job in our production system every week or two. Sometimes we don't get this exception for few weeks. In case of failures, We just retry the job and the exception will go away. We are not sure what is the cause of the failure but we suspect that MySQL driver is causing this issue.

We have a column which is declared as DECIMAL(6,3) in the table and mapped to a Float type in the hibernate domain object. This is the common behavior we found in all the exceptions we got. Column names varies but their database type and java type are same as the above one. We suspect that driver has issues in converting decimal to a Float in our hibernate object. But what is strange is that it is not a overflow. We checked the accounts which had this problem and they had 0.0 in their column value.


Nov 30 01:16:03,180 ERROR rollSettlementBucketsJob [workerThreadPool-1-4] [org.hibernate.util.JDBCExceptionReporter] 465 - '0.0' in column '82' is outside valid range for the datatype FLOAT.
Nov 30 01:16:03,218 ERROR rollSettlementBucketsJob [workerThreadPool-1-4] [com.om.dh.batch.item.adapter.AbstractDelegatingAdapter] 103 - processing complete for 1000000055781 elapsed=74ms exception=org.hibernate.exception.DataException: could not load an entity: [com.om.dh.accountmgmt.domain.account.Account#1000000055781]
org.hibernate.exception.DataException: could not load an entity: [com.om.dh.accountmgmt.domain.account.Account#1000000055781]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1895)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:121)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:863)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:95)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.om.dh.accountmgmt.domain.account.Account_$$_javassist_98.getAccountPortfolio(Account_$$_javassist_98.java)
at com.om.dh.account.balance.service.impl.RollAccountServiceImpl.roll(RollAccountServiceImpl.java:55)
at com.om.dh.account.balance.service.impl.RollAccountServiceImpl.roll(RollAccountServiceImpl.java:45)
at sun.reflect.GeneratedMethodAccessor1496.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy283.roll(Unknown Source)
at SC.write(SC.java:5)
at com.om.dh.batch.item.adapter.AbstractDelegatingItemWriterAdapter.write(AbstractDelegatingItemWriterAdapter.java:67)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:155)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:136)
at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor$3.doWithRetry(FaultTolerantChunkProcessor.java:227)
at org.springframework.batch.retry.support.RetryTemplate.doExecute(RetryTemplate.java:230)
at org.springframework.batch.retry.support.RetryTemplate.execute(RetryTemplate.java:180)
at org.springframework.batch.core.step.item.BatchRetryTemplate.execute(BatchRetryTemplate.java:213)
at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor.write(FaultTolerantChunkProcessor.java:300)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:193)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:70)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:67)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:352)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:212)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:239)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198)
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:108)
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '0.0' in column '82' is outside valid range for the datatype FLOAT.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:999)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.throwRangeException(ResultSetImpl.java:7819)
at com.mysql.jdbc.ResultSetImpl.getFloatFromString(ResultSetImpl.java:2542)
at com.mysql.jdbc.ResultSetImpl.getFloat(ResultSetImpl.java:2501)
at com.mysql.jdbc.ResultSetImpl.getFloat(ResultSetImpl.java:2519)
at org.jboss.resource.adapter.jdbc.WrappedResultSet.getFloat(WrappedResultSet.java:666)
at org.hibernate.type.FloatType.get(FloatType.java:46)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:583)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2124)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
at org.hibernate.loader.Loader.getRow(Loader.java:1230)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)


Any clues?


thanks in advance,
Ramkumar

Why my connection from JAVA to MySQL is so unstable? (no replies)

$
0
0
Hi!

I'm developing an application based on using JAVA SE and MySQL. My database uses UTF8 settings. I connect to the database from JAVA with the following statement: db = (Connection) DriverManager.getConnection("jdbc:mysql://" + url + "/" + databasename + "?useUnicode=true&characterEncoding=UTF8",login, pass); In this case, everything works correctly, but very unstable. Sometimes the connection is lost and the following error message is returned. Has someone experienced the same problem? Thanks!

Could not initialize the database. Please verify your login and password.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at SystClasses.PasswordForm.connectToDB(PasswordForm.java:138)
at SystClasses.PasswordForm.access$100(PasswordForm.java:34)
at SystClasses.PasswordForm$1.actionPerformed(PasswordForm.java:117)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
... 41 more

No updated Data avaiable until New Connection (1 reply)

$
0
0
Hi to all, iam new.

I having a Problems, after insert Data to my Table contacs,
The Insertaction works well, and if i make a SELECT * FROM Contacts
via MySQL Workbench i can see the New Data, but i have no choice to geht
the new Data thadt i have just inserted toe the Contacts Table i cannot
get it with a Simple Select * from contacts.

I only get the New Data, if i terminate my Programm and do a complete
new JDBC Connection.

Connection Details:
Using Glassfish v3, Pooled Datasource (JNDI)
and Prepared Statements
Unsing MySQL Connector/J: "mysql-connector-java-5.1.14.tar.gz"
(but have Tested since 5.1.14 / 13 / 12 and there are no changes noticed)

Any Ideas?

Thx for any Help!

Error calling StoredProcedure with parameters (3 replies)

$
0
0
I have set up a new MySql database and defined a test stored procedure. I can call stored procedures that take no parameters, but if I call one that takes at least one parameter I get an index exception.

       Connection c = connector.getConnection();
       CallableStatement cs = c.prepareCall("{ call fms.OneParam(?)}");
       cs.registerOutParameter(1, java.sql.Types.INTEGER);
       cs.execute();   <== FAILS WITH SQLException
       int param1 = cs.getInt(1);
       return param1;

The exception I receive is the following:
java.sql.SQLException Parameter index of 1 is out of range (1, 0)

The stored procedure looks like:
CREATE DEFINER=`root`@`localhost` PROCEDURE `OneParam`(
        OUT ecode INT)
BEGIN

 SET ecode = 5;

END
And the user I am connecting with has execute permissions on the stored procedures.

Additional info:
1) Installed using xampp
2) Using MySql 5.5

More Info
-----------
I noticed that if I go into MySql Admin and look at the stored procedures as 'root' everything is fine. But if I log in as 'webuser' I cannot see the body of the stored procedures. I have assigned ALL privileges to the user, but he still cannot see the body. I exported the database and changed the creator to 'webuser' restored the database and still could not see the procedure body as 'webuser'.

Yet More info
-------------
I have removed the calls to the stored procedures and put the SQL directly in my code and I still get the same error message.

      Connection c = null;
      PreparedStatement ps = null;
      try {
         c = connector.getConnection();
         ps = c.prepareStatement(INSERT_USER_REC);
         ps.setString(1, reginfo.getLicKey());
         ps.setString(2, reginfo.getEmailAddress().toString());
         ps.setString(3, reginfo.getFirstName());
         ps.setString(4, reginfo.getLastName());
         int rtn = ps.executeUpdate();
      } finally {
         if (c != null) { connector.closeConnection(c); }
         if (ps != null) { ps.close(); } // also closes the result set
      }

Are MySQL jdbc connectors downwards compatible? (1 reply)

$
0
0
Can I use a newer MySQL Java JDBC connectors (for usage in Eclipse) downwards compatible with older MySQL DBs ?


Peter

Connector/MXJ (1 reply)

$
0
0
Hi everybody,

I'm developping a Java application which uses data stored in a MySQL Community Server running on my computer.

Now I want to use the Connector/MXJ to have an embedded database in my application. To do this I follow this procedure http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-usagenotes-customdb.html.

The following Jar files are in the classpath
- mysql-connector-java-5.1.13-bin.jar
- mysql-connector-mxj-db-gpl-5.0.11.jar
- mycustom-mysql-connector-mxj-db-gpl-5.0.11-files.jar
- aspectjrt.jar

The problem is when I when I run my Java application I'have got the following error messages :

[C:\Users\sebastien\AppData\Local\Temp\mysql-c.mxj\bin\mysqld.exe][--no-defaults][--console][--port=3336][--socket=mysql.sock][--basedir=C:\Users\sebastien\AppData\Local\Temp\mysql-c.mxj][--datadir=C:\Users\sebastien\AppData\Local\Temp\mysql-c.mxj\data][--pid-file=C:\Users\sebastien\AppData\Local\Temp\mysql-c.mxj\data\MysqldResource.pid]
[MysqldResource] launching mysqld (driver_launched_mysqld_1)
[MysqldResource] mysqld running as process: 3404
101208 11:14:12 [Note] Plugin 'FEDERATED' is disabled.
InnoDB: Error: log file .\ib_logfile0 is of different size 0 25165824 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
101208 11:14:12 [ERROR] Plugin 'InnoDB' init function returned error.
101208 11:14:12 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
101208 11:14:13 [Note] Event Scheduler: Loaded 0 events
101208 11:14:13 [Note] C:\Users\sebastien\AppData\Local\Temp\mysql-c.mxj\bin\mysqld.exe: ready for connections.
Version: '5.1.40-community' socket: '' port: 3336 MySQL Community Server (GPL)
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table engine 'InnoDB'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2409)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2327)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2312)
at worker.WorkerDb.clean(WorkerDb.java:774)
at controller.Controller.clean(Controller.java:64)
at controller.Controller.updateAll(Controller.java:52)
at controller.Controller.<init>(Controller.java:45)
at main.Main.main(Main.java:24)

Thanks for your advices!
sébastien

Problem with connection pooling (1 reply)

$
0
0
Hi,

I'm running into the following exception with connection pooling when trying to get a connection from the pool:

Cannot create JDBC driver of class '' for connect URL 'null'
java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:253)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at nl.timeware.data.TDataBase.connectFromPool(TDataBase.java:83)
.....

In my application's /WEB-INF/web.xml I have:
<resource-ref>
<description>MySQL DB Connection pooling</description>
<res-ref-name>jdbc/mysqldb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

In my application's /META-INF/context.xml I have:
<Context>
<Resource name="jdbc/mysqldb" auth="Container" type="javax.sql.DataSource"
maxActive="40" maxIdle="10" maxWait="5000"
testWhileIdle="true" timeBetweenEvictionRunsMillis="300000"
username="mysqluser" password="mysqlpswd" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/mysqldb?useOldAliasMetadataBehavior=true"/>
</Context>

I'm connecting as follows:
public void connectFromPool() throws Exception
{ InitialContext jndiContext = new InitialContext();
if (jndiContext == null)
throw new Exception("No JNDI context");
DataSource ds = (DataSource)jndiContext.lookup("java:/comp/env/jdbc/mysqldb");
if (ds == null)
throw new Exception("No data source available");
connection = ds.getConnection(); // <-- this is were the above exception occurs
connection.setAutoCommit(true);
}

I know the database name, MySQL username and password are working correctly. The same configuration works OK on another host
(with slightly different minor software version numbers). I have the latest mysql-connector-java-5.1.14-bin on the tomcat\lib directory.

Where should I go from here, what can I check?

Thanks, regards,
Paul.
Viewing all 884 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>