MySql and PreparedStatement
I am using WSAD 5.1 (Websphere Application Developer). My database is MySQL. I have set up a datasource that connects to MySQL in WSAD. I have a simple code that connects to the datasource using InitialContext.lookup.
My Code :
Connection conn = null;
DataSource ds = null;
try {
InitialContext ctx = new InitialContext();
ds = (DataSource)ctx.lookup("jdbc/ds1");
conn = ds.getConnection();
} catch (NamingException e) {
e.printStackTrace();
//POINT 1
PreparedStatement ps = conn.prepareStatement("select * from table1");
ResultSet rs = ps.executeQuery( );
rs.next();
System.out.println("Value -> " + rs.getString(1));
Error occurs at POINT 1. The error that im getting is this :
java.sql.SQLException: Parameter with index of 1 is not set.
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.enforceStatementProperties(WSJdbcPreparedStatement.java:426)
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeQuery(WSJdbcStatement.java:429)
The weird thing is, if I use Statement instead of PreparedStatement, it works. I dont know whats wrong. Please, anyone, help.
By the way, I need to use PreparedStatement, because im planning to use the same method with different queries, so some have "?" and some dont.
Please.
If it's the same code and the same database then your configurations aren't the same on the various machines. Make the machine where it "fails" (whatever that means) be configured the same way as the other machines where it doesn't.
You mentioned Websphere, so making sure the configurations are the same is going to be ridiculously difficult. But that's what you need to do.
Similar Messages
-
Too many connections - even after closing ResultSets and PreparedStatements
I'm getting a "Too many connections" error with MySQL when I run my Java program.
2007-08-06 15:07:26,650 main/CLIRuntime [FATAL]: Too many connections
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Too many connections
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:921)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3269)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1182)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2670)I researched on this and found out that I wasn't closing the ResultSet and the PreparedStatement.
The JDBC connection is closed by a central program that handles connections (custom connection pooling).
I added the code to close all ResultSets and PreparedStatements, and re-started MySQL as per the instructions here
but still get "Too many connections" error.
A few other things come to mind, as to what I may be doing wrong, so I have a few questions:
1) A few PreparedStatements are created in one method, and they are used in a 2nd method and closed in the 2nd method
does this cause "Too many connections" error?
2) I have 2 different ResultSets, in nested while loops where the outer loop iterates over the first ResultSet and
the inner loop iterates over the second ResultSet.
I have a try-finally block that wraps the inner while loop, and I'm closing the second ResultSet and PreparedStement
in the inner while loop.
I also have a try-finally block that wraps the outer while loop, and I'm closing the first ResulSet and PreparedStatement
in the outer while loop as soon as the inner while loop completes.
So, in the above case the outer while loop's ResultSet and PreparedStatements remain open until the inner while loop completes.
Does the above cause "Too many connections" error?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following is relevant sections of my code ( it is partially pseudo-code ) that shows the above 2 cases:
init( Connection jdbcConnection ){
String firstSQLStatement = "....";
PreparedStatement ps1 = jdbcConnection.prepareStatement( firstSQLStatement );
String secondSQLStatement = "....";
PreparedStatement ps2 = jdbcConnection.prepareStatement( secondSQLStatement );
String thirdSQLStatement = "....";
PreparedStatement ps3 = null;
ResultSet rsA = null;
try{
ps3 = jdbcConnection.prepareStatement( thirdSQLStatement );
rsA = ps3.executeQuery();
if( rsA.next() ){
rsA.getString( 1 );
}finally{
if( rsA != null )
rsA.close();
if( ps3 != null )
ps3.close();
//Notice, how ps1 and ps2 are created here but not used immediately, but only ps3 is
//used immediately.
//ps1 and ps2 are used in another method.
run( Connection jdbcConnection ){
ResultSet rs1 = ps1.executeQuery();
try{
while(rs1.next()){
String s = rs1.getString();
ps2.setString(1, s);
ResultSet rs2 = ps2.executeQuery();
try{
while(rs2.next()){
String s2 = rs2.getString();
}finally{
if( rs2 != null )
rs2.close();
if( ps2 != null )
ps2.close();
}catch( Exception e ){
e.printStackTrace();
}finally{
if( rs1 != null )
rs1.close();
if( ps1 != null )
ps1.close();
//Notice in the above case rs1 and ps1 are closed only after the inner
//while loop completes.
}I appreciate any help.Thanks for your reply.
I will look at the central connection pooling mechanism ( which was written by someone else) , but that is being used by many other Java programs others have written.
They are not getting this error.
An addendum to my previous note, I followed the instructions here.
http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html
There's probably something else in my code that is not closing the connection.
But I just wanted to rule out the fact that opening a PreparedStatement in one method and closing it in another is not a problem.
Or, if nested ResultSet loops don't cause the problem.
I've read in a few threads taht "Too many connections" can occur for unclosed RS and PS , and not just JDBC connections. -
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.
-
Issue in bringing up CRS on ATG 10.1.1 with MySQL and Weblogic 10.3
Hello,
I am trying to bring up Commerce Reference Store as part of my evaluation using MySQL (bundled with ATG) and WebLogic 10.3.
I followed the ATG Documentation on CRS with WebLogic and MySQL and I could not proceed because of the below error log. I keep getting error in OnlineCreateServerInstanceTask of CIM. I believe it should be some configuration problem, but could not think of any.
As part of the installation, I use C:\jdk1.6.0_25. I verified my weblogic server is up through the admin console. I started MySQL before running the eval batch. Apart from starting MySQL server, I did not make any datasource/database configuration changes for ATG. I have not run any other scripts to configure MySQL too.
Please guide me to resolve the problem.
C:\ATG\ATG10.1.1\CommerceReferenceStore\Store\eval>configureEval.bat
Do you wish to run the CRS evaluation installation? [Y/N]: y
Do you wish to use an existing database for the CRS evaluation? [Y/N]: n
The CRS evaluation install will attempt to create the database. Press [Return] t
o continue or any other key to quit:
Enter mysql database connection details
Enter user name: admin
Enter user password: admin
Enter database name: crsprod
Enter 'root' user password:
Creating database...
Finished database creation
Enter weblogic admin server URL: http://localhost:7001
Enter weblogic admin server username: weblogic
Enter weblogic admin server password: weblogic123
Buildfile: C:\ATG\ATG10.1.1\CommerceReferenceStore\Store\eval\evalbuild.xml
all:
[copy] Copying 1 file to C:\ATG\ATG10.1.1\CommerceReferenceStore\Store\eval
[delete] Deleting: C:\ATG\ATG10.1.1\CommerceReferenceStore\Store\eval\cimOut.
cim.tmp
BUILD SUCCESSFUL
Total time: 0 seconds
Application Server: weblogic
The following installed ATG components are being used to launch:
ATGPlatform version 10.1.1 installed at C:\ATG\ATG10.1.1
Created "C:\ATG\ATG10.1.1\home\CIM\startDynamo.jar" in 15,273ms.
Nucleus running
atg.cim.productconfig.productselector.ProductSelectionContextTask starting...
(Searching for products... done.)
atg.cim.productconfig.productselector.ProductSelectionContextTask finished.
atg.cim.productconfig.appserver.AppServerSelectTask starting...
atg.cim.productconfig.appserver.AppServerSelectTask finished.
atg.cim.productconfig.appserver.AppServerPathTask starting...
atg.cim.productconfig.appserver.AppServerPathTask finished.
atg.cim.productconfig.appserver.DomainPathTask starting...
atg.cim.productconfig.appserver.DomainPathTask finished.
atg.cim.productconfig.appserver.UrlTask starting...
atg.cim.productconfig.appserver.UrlTask finished.
atg.cim.productconfig.appserver.UsernameTask starting...
atg.cim.productconfig.appserver.UsernameTask finished.
atg.cim.productconfig.appserver.PasswordTask starting...
atg.cim.productconfig.appserver.PasswordTask finished.
atg.cim.productconfig.appserver.AppServerSelectionPersistenceTask starting...
atg.cim.productconfig.appserver.AppServerSelectionPersistenceTask finished.
atg.cim.database.CreateSchemaTask starting...
atg.cim.database.CreateSchemaTask finished.
atg.cim.database.ImportDataTask starting...
Combining template tasks...Success
Importing (1 of 1) /CIM/tmp/import/nonswitchingCore-import1.xml:
/CommerceReferenceStore/Store/Storefront/data/pricelists.xml to /atg/commerce/pr
icing/priceLists/PriceLists
/CommerceReferenceStore/Store/Storefront/data/stores.xml to /atg/store/stores/St
oreRepository
/CommerceReferenceStore/Store/Storefront/data/catalog-i18n.xml to /atg/commerce/
catalog/ProductCatalog
/CommerceReferenceStore/Store/Storefront/data/pricelists-i18n.xml to /atg/commer
ce/pricing/priceLists/PriceLists
/CommerceReferenceStore/Store/Storefront/data/sites.xml to /atg/multisite/SiteRe
pository
/CommerceReferenceStore/Store/Storefront/data/sites-i18n.xml to /atg/multisite/S
iteRepository
/CommerceReferenceStore/Store/Storefront/data/promos-i18n.xml to /atg/commerce/c
atalog/ProductCatalog
/CommerceReferenceStore/Store/Storefront/data/seotags-i18n.xml to /atg/seo/SEORe
pository
/CommerceReferenceStore/Store/Storefront/data/wishlists.xml to /atg/commerce/gif
ts/Giftlists
/CommerceReferenceStore/Store/Storefront/data/inventory.xml to /atg/commerce/inv
entory/InventoryRepository
/CommerceReferenceStore/Store/Storefront/data/users.xml to /atg/userprofiling/Pr
ofileAdapterRepository
/CommerceReferenceStore/Store/Storefront/data/orders.xml to /atg/commerce/order/
OrderRepository
/CommerceReferenceStore/Store/Storefront/data/orders-i18n.xml to /atg/commerce/o
rder/OrderRepository
/CommerceReferenceStore/Store/Storefront/data/storetext-i18n.xml to /atg/store/s
tores/StoreRepository
/CommerceReferenceStore/Store/Storefront/data/claimable-i18n.xml to /atg/commerc
e/claimable/ClaimableRepository
... > Success
All Imports Completed Successfully
atg.cim.database.ImportDataTask finished.
atg.cim.worker.common.PropertyFileClearPersistanceTask starting...
atg.cim.worker.common.PropertyFileClearPersistanceTask finished.
atg.cim.productconfig.serverinstance.ServerInstanceNameTask starting...
atg.cim.productconfig.serverinstance.ServerInstanceNameTask finished.
atg.cim.productconfig.serverinstance.PortBindingsSelectTask starting...
atg.cim.productconfig.serverinstance.PortBindingsSelectTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.worker.common.MapPropertyFileCreatorTask starting...
atg.cim.worker.common.MapPropertyFileCreatorTask finished.
atg.cim.productconfig.serverinstance.MakeServerInstanceFromPatternTask starting.
atg.cim.productconfig.serverinstance.MakeServerInstanceFromPatternTask finished.
atg.cim.productconfig.appassembly.EarFileNameTask starting...
atg.cim.productconfig.appassembly.EarFileNameTask finished.
atg.cim.productconfig.deploy.weblogic.OnlineCreateServerInstanceTask starting...
Error Executing Batch File
atg.cim.worker.TaskException: Error deploying to weblogic
atg.cim.worker.TaskException: Error exececuting batch file
at atg.cim.flow.CimFlowCreator.startHeadlessCimFlow(CimFlowCreator.java:
130)
at atg.cim.Launcher.startCimFlow(Launcher.java:278)
at atg.cim.Launcher.main(Launcher.java:99)
Caused by: atg.cim.worker.TaskException: Error deploying to weblogic
at atg.cim.worker.Task.handleException(Task.java:72)
at atg.cim.productconfig.deploy.weblogic.OnlineCreateServerInstanceTask.
execute(OnlineCreateServerInstanceTask.java:159)
at atg.cim.headless.HeadlessExecutorImpl.executeTasks(HeadlessExecutorIm
pl.java:150)
at atg.cim.headless.HeadlessExecutorImpl.populateAndExecuteHeadlessTasks
(HeadlessExecutorImpl.java:140)
at atg.cim.batch.BatchChooserExecutor.populateAndExecuteHeadlessTasks(Ba
tchChooserExecutor.java:169)
at atg.cim.flow.CimFlow.headlessFlow(CimFlow.java:116)
at atg.cim.flow.CimFlowCreator.startHeadlessCimFlow(CimFlowCreator.java:
120)
... 2 more
Caused by: C:\ATG\ATG10.1.1\CIM\plugins\Base\ant\cim-ant.xml:348: The following
error occurred while executing this line:
C:\ATG\ATG10.1.1\CIM\plugins\Base\ant\cim-ant.xml:254: The following error occur
red while executing this line:
C:\ATG\ATG10.1.1\CIM\plugins\Base\ant\cim-ant.xml:214: exec returned: 1
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(Projec
tHelper.java:541)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.jav
a:394)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at atg.cim.task.ant.utility.AntExecutionWrapper.executeAntTarget(AntExec
utionWrapper.java:167)
at atg.cim.worker.AntTask.executeAntTarget(AntTask.java:115)
at atg.cim.productconfig.deploy.weblogic.OnlineCreateServerInstanceTask.
execute(OnlineCreateServerInstanceTask.java:155)
... 7 more
Caused by: C:\ATG\ATG10.1.1\CIM\plugins\Base\ant\cim-ant.xml:254: The following
error occurred while executing this line:
C:\ATG\ATG10.1.1\CIM\plugins\Base\ant\cim-ant.xml:214: exec returned: 1
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(Projec
tHelper.java:541)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.jav
a:394)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.jav
a:391)
... 20 more
Caused by: C:\ATG\ATG10.1.1\CIM\plugins\Base\ant\cim-ant.xml:214: exec returned:
1
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:636)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:662)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:487)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.jav
a:391)
... 34 more
Nucleus shutting down
Nucleus shutdown complete
Thanks.This error is resolved after following the logs in C:\ATG\ATG10.1.1\CIM\log\cim.log. The root cause is I used http as protocol instead of t3 while specifying weblogic admin url.
http://localhost:7001 instead of t3://localhost:7001
Thanks. -
Performance with MySQL and Database connectivity toolbox
Hi!
I'm having quite some problems with the performance of MySQL and Database connectivity toolbox. However, I'm very happy with the ease of using database connectivity toolbox. The background is:
I have 61 variables (ints and floats) which I would like to save in the MySQL-database. This is no problem, however, the loop time increases from 8ms to 50ms when using the database. I have concluded that it has to do with the DB Tools Insert Data.vi and I think that I have some kind of performance issue with this VI. The CPU never reach more the 15% of its maximum performance. I use a default setup and connect through ODBC.
My questions are:
1. I would like to save 61 variables each 8-10ms, is this impossible using this solution?
2. Is there any way of increasing the performance of the DB Tools Insert Data.vi or use any other VI?
3. Is there any way of adjusting the MySQL setup to achieve better performance?
Thank you very much for your time.
Regards,
MattiasFirst of all, thank you very much for your time. All of you have been really good support to me.
>> Is your database on a different computer? Does your loop execute 61 times?
Database is on the same computer as the MySQL server.
The loop saves 61 values at once to the database, in one SQL-statement.
I have now added the front panel and block diagram for my test-VI. I have implemented the queue system and separate loops for producer and consumer. However, since the queue is building up faster then the consumer loop consumes values, the queue is building up quite fast and the disc starts working.
The test database table that I add data to is created by a simple:
create table test(aa int, bb char(15));
...I'm sure that this can be improved in some way.
I always open and close the connection to the database "outside the loop". However, it still takes some 40-50 ms to save the data to the database table - so, unfortunatly no progress to far. I currently just want to save the data.
Any more advise will be gratefully accepted.
Regards,
Mattias
Message Edited by mattias@hv on 10-23-2007 07:50 AM
Attachments:
front panel 2.JPG 101 KB
block diagram.JPG 135 KB -
MySQL and JDBC Classpath errors
I am new to Java and installed MySql and also installed mysql-connectorJ driver. I can compile the code below, but when I go to run it, I get "Exception in thread "main" java.lang.NoClassDefFoundError: JDBCDemo/class" error. I can't figure out what I am doing wrong.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBCDemo {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
catch (Exception e)
e.printStackTrace();
I have a the following environment variable called MySQL_Driver located at "C:\Program Files\Java\jdk1.5.0_06\lib".
Path = "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared;%JAVA_HOME%;%JAVA_HOME%\lib;%JAVA_VM%\bin;%JAVA_VM%\lib;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\QuickTime\QTSystem\;%MySQL_Driver%"What is your CLASSPATH set to as you need to make sure that the driver is in the path as well as the directory/jar where the JDBCDemo app lives.
Try explictly specifying everything via the -classpath option on your java command line -
Using MySql and PHP with Dreamweaver on a Mac
Hello all,
As always if the answers to these questions are obscenely
obvious please humour me.
I use XHTML and CSS in my websites and realise that it is
time that I dabbled with SSI. So I've started using PHP.
However, I have been following the installation directions of
MySql and am running into problems. I am installing the relavent
software and am then unable to find it on my Mac, the startup files
are there but the actual MySql data appears to not be installed
despite my computer telling me it is...... I am using a G3 running
OSX 10.4 is this good enough? I noticed talk of needing a PowerPC
or Intel mac. Is this the case?
Also, would I need MySql installed on my actual computer if
the my servers have it already? And does Dreamweaver 8 have both of
these programs installed as standard?
If you could help out I would be very appreciative as I would
like to learn this stuff and I appear to be struggling at the
outset....
Cheers
M.AM.A.Wilson wrote:
> However, I have been following the installation
directions of MySql and am
> running into problems. I am installing the relavent
software and am then unable
> to find it on my Mac, the startup files are there but
the actual MySql data
> appears to not be installed despite my computer telling
me it is...... I am
> using a G3 running OSX 10.4 is this good enough? I
noticed talk of needing a
> PowerPC or Intel mac. Is this the case?
MySQL is a relational database management system that
comprises a
database server and several utility programs. Although you
install it
like any other program on a Mac, the similarity stops there.
First, the point about PowerPC and Intel Macs is that there
are
different versions of the MySQL installer for each type of
processor.
I'm pretty sure that a G3 is OK, but you must choose the
PowerPC version
of MySQL, not the 64-bit or x86 (Intel Mac) version.
Once you have installed MySQL, you need to drag the
MySQL.PrefPane icon
from the disk image onto your System Preferences. This
installs a
Preference Pane that enables you to start and stop MySQL. The
Preference
Pane has an option to start up MySQL automatically, but in my
experience, it doesn't work on Tiger. You need to open the
Preference
Pane, and click Start MySQL Server each time you start your
computer.
The best way to work with MySQL is to use a graphical
interface, such as
phpMyAdmin. As Osgood has mentioned, I have written a book
about PHP and
Dreamweaver, which goes into all the necessary details. It's
also very
Mac-friendly with separate instructions where necessary for
PC and Mac.
More details here:
http://foundationphp.com/dreamweaver8/
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/ -
Database setup with MySQL and PHP question
Hello all,
I recently had a problem getting a report to work for a site I was updating. This site is written in PHP with a MySQL database. The application is to track customer calls to auto repair stores. The database has a lot of foreign keys because they wanted to update information in only one spot and have multiple records be updated all at once. So, I've got all the information from individual calls saved in the call_log table, and have foreign keys to reference information in other tables (for example this table lists what store received the call referencing the store table). If a store changes locations, they want to have reports automatically update with the new address, connection to conversation number, etc.
In one of the responses to my question on how to get this report to work, I was told that this could be done without using foreign keys (by Normalizing the database using mapping tables). I am still a newbie to MySQL, and after looking though a lot of manuals, tutorials, and forum posts, I am more confused now than ever.
I got the report to work using the foreign keys, but I would like to learn what I should have done with the database (and how to get the information displayed).
So for example one report would be displaying the following:
Store Reason for the Customer Call
breaks oil change shocks tune up total calls
5636 - Bloomington 2 4 0 2 8
8875 - Duluth 1 6 4 8 19
with links on the store name to pull up the information on that specific store. How would I change the database (listed below) to do this without foreign keys? Any help would be greatly appreciated.
call_log (table that contains the following:)
call_id
conv_number
date
camp_type (foreign key to the campaign table so it displays the campaign_id)
reason (foreign key to the call_reason table so it displays the reason_id)
location (foreign key to the store table so it displays the store_id)
associate
call_summary
trainig_issue (foreign key to the training_points table so it displays the training_key_id)
visit_closed
example (foreign key to the example_type table so it displays the example_id)
campaign (table that contains the following:)
campaign_id
campaign_name
campaign_promotion
campaign_coupon
campaign_startdate
campaign_enddate
call_reason (table that contains the following:)
reason_id
reason
store (table that contains the following:)
store_id
store_number
store_address
store_city
store_state
store_postalcode
store_name
store_phone
store_email
store_mgr
training_points (table that contains the following:)
training_key_id
key_issue
policy
example_type (table that contains the following:)
example_id
example_name
example_image
Thank you very much.Frankly, that is way to much of a question to be answered in detail on a forum... There's a lot involved and a lot of general database understanding required. I would highly recommend:
Database Design for Mere Mortals: A Hands-On Guide to Relational Database Design, Second Edition -- by Michael J. Hernandez
This is an invaluable book to get you going in the right direction and on a firm foundation.
Lawrence *Adobe Community Expert*
www.Cartweaver.com
Complete Shopping Cart Application for
Dreamweaver, available in ASP, PHP and CF
www.twitter.com/LawrenceCramer -
Trying to run PHP, Mysql and Apache
Hey guys, Basically Im at university and doing a web development project and i need to use mysql and php, and someone told me leopard already comes with it? Does anyone know how i can get it to work correctly? any steps from the beginning? - am new to macs
Cheers
Krupshello, I will suggest you to follow the instructions set up by Marc Lyianage in his website, the url is http://www.entropy.ch/software/macosx/ there you will find a page for setting up php5 (it comes preinstalled in leopard) and it has a also a package installer for mysql very easy to set up.
-
Installing php, mysql and apache
Hey guys, Basically Im at university and doing a web development project and i need to use mysql and php, and someone told me leopard already comes with it? Does anyone know how i can get it to work correctly? any steps from the beginning? - am new to macs
Cheers
KrupsThis web page:
http://www.macosxhints.com/article.php?story=20071030153912813
claims to tell you how to do it, though after 12 hours of working on this today I seem to be no closer. -
How to bulk import data into CQ5 from MySQL and file system
Is there an easy way to bulk import data into CQ5 from MySQL and file system? Some of the files are ~50MB each (instrument files). There are a total of ~1,500 records spread over about 5 tables.
ThanksWhat problem are you having writing it to a file?
You can't use FORALL to write the data out to a file, you can only loop through the entries in the collection 1 by 1 and write them out to the file like that.
FORALL can only be used for SQL statements. -
DataSource and PreparedStatement
I am using DataSource and PreparedStatement in weblogic8.1 for a J2EE application.
It works if we use only EJB..but if we use enterprise app. i.e. servlets,jsp,ejb etc.. it does not work.
Can somebody tell the reason behind it??Why do you feel this is an issue with the PreparedStatements and not just the DataSource? Are you sure you have configured the DataSource correctly for your platforms outside your ejb container?
-
What is the different between statement and preparedstatement?
hi,
recently i have attended a telephonic interview. they asked me what is the different between statement and preparedstatement? and when u will use them? Hi! can any one say me the original difference??sorry dear,
i am already shortlisted. and monday is my HR round.
. Every 1 is not like u.
So you have read the examples and explanations that you found when you googled, and you have read the javadoc and you still don't understand? And you are shortlisted? For what? I hope you won't do server programming.
I will give you a few hints.
Escaping of data
Storing of dates
Safer
Faster -
Performance Problem - MS SQL 2K and PreparedStatement
Hi all
I am using MS SQL 2k and used PreparedStatement to retrieve data. There is strange and serious performance problem when the PreparedStatement contains "?" and using PreparedStatement.setX() functions to set its value. I have performed the test with the following code.
for (int i = 0; i < 10; i ++) {
try {
con = DBConnection.getInstance();
statement = con.prepareStatement("SELECT * FROM cardno WHERE car_no = '" + cardNo + "'");
// statement = con.prepareStatement("SELECT * FROM cardno WHERE car_no = ?");
// statement.setString(1, cardNo);
rs = statement.executeQuery();
if (rs.next()) {
catch(SQLException e) {
e.printStackTrace();
finally {
try {
rs.close();
statement.close();
catch(SQLException e) {
e.printStackTrace();
Iteration Time (ms)
1 961
10 1061
200 1803
for (int i = 0; i < 10; i ++) {
try {
con = DBConnection.getInstance();
// statement = con.prepareStatement("SELECT * FROM cardno WHERE car_no = '" + cardNo + "'");
statement = con.prepareStatement("SELECT * FROM cardno WHERE car_no = ?");
statement.setString(1, cardNo);
rs = statement.executeQuery();
if (rs.next()) {
catch(SQLException e) {
e.printStackTrace();
finally {
try {
rs.close();
statement.close();
catch(SQLException e) {
e.printStackTrace();
Iteration Time (ms)
1 1171
10 2754
100 18817
200 36443
The above test is performed with DataDirect JDBC 3.0 driver. The one uses ? and setString functions take much longer to execute, which supposed to be faster because of precompilation of the statement.
I have tried different drivers - the one provided by MS, data direct and Sprinta JDBC drivers but all suffer the same problem in different extent. So, I am wondering if MS SQL doesn't support for precompiled statement and no matter what JDBC driver I used I am still having the performance problem. If so, many O/R mappings cannot be used because I believe most of them if not all use the precompiled statement.
Best regards
EdmondEdmond,
Most JDBC drivers for MS SQL (and I think this includes all the drivers you tested) use sp_executesql to execute PreparedStatements. This is a pretty good solution as the driver doesn't have to keep any information about the PreparedStatement locally, the server takes care of all the precompiling and caching. And if the statement isn't already precompiled, this is also taken care of transparently by SQL Server.
The problem with this approach is that all names in the query must be fully qualified. This means that the driver has to parse the query you are submitting and make all names fully qualified (by prepending a db name and schema). This is why creating a PreparedStatement takes so much using these drivers (and why it does so every time you create it, even though it's the same PreparedStatement).
However, the speed advantage of PreparedStatements only becomes visible if you reuse the statement a lot of times.
As about why the PreparedStatement with no placeholder is much faster, I think is because of internal optimisations (maybe the statement is run as a plain statement (?) ).
As a conclusion, if you can reuse the same PreparedStatement, then the performance hit is not so high. Just ignore it. However, if the PreparedStatement is created each time and only used a few times, then you might have a performance issue. In this case I would recommend you try out the jTDS driver ( http://jtds.sourceforge.net ), which uses a completely different approach: temporary stored procedures are created for PreparedStatements. This means that no parsing is done by the driver and PreparedStatement caching is possible (i.e. the next time you are preparing the same statement it will take much less as the previously submitted procedure will be reused).
Alin. -
Secure mysql and ease of programming
Hello,
How/what do I set up so that I do not have to include in all my jsp files the connection information to my mysql database for my application? It is tedious to have to set up the try...catch..finally stuff everytime I want to have a query in my jsp files. I am using mysql and jakarta-tomcat-4.0.4.
DavidWhy don't you write a Database class, then when you want to access the database you can just create an instance of this class and call a method that does the connection, the trys & catches etc.
eg you could have a method with signature
public ResultSet exQuery(String query) etc etc.
Much better practice to only have one class that accesses the database - esp if you want to change drivers, connection methods etc in the future.
Maybe you are looking for
-
Printing Resource Name Form View
Hi there, I am using Project 2013 Professional on SP1 with all the updates applied. I am trying to print the resource name form so I can give all the business users involved in the project a list of thier tasks, when they are due, and how much effort
-
Videos no longer play in itunes 12
Upon downloading the new itunes 12, videos in my library no longer play on my computer. The second screen come up and looks like it wants to start but stays black. The video play button ison bu the time toggle doesn't move. Any ideas?
-
Sudden airport problem - due to new networks in the building?
I've been using my airport extreme network for some time, without any problems. My macbook suddenly stopped recognising the network - although my iphone and other computers continue to use it without any problems. The network name no longer appears i
-
Java math is totally not working!
Hi! Ok for some homework I'm doing I've got to like, do some math stuff :( I do this double d = 3.1 - 2.2; System.out.println(d); and it prints out 0.8999999999999999. I like, did the same thing on my calculator and it told me the answer is 0.9! Hell
-
Hi Experts, It would be great if you can guide me on a way to include a 'Z' infotype as a link in ESS. A step by step explanation would be of great help as we dont have any strong ABAP WebDynpro support. Regards Kruna