Hallo,
ich bin ein wenig am Verzweifeln mit diesem Codestück.
die Variable sql sieht vor dem execute so aus:
Und funktioniert auch auf meinem MySQL system auf der Commandozeile:
Wenn ich das erste Codestück allerdings ausführe bekomme ich diesen Fehler:
Der Treiber ist "com.mysql.jdbc.Driver" und wird c3p0 übergeben.
Ich bin ein völlig ratlos im Moment. Vielleicht hatte hier ja schon jemand das Problem und kann mir weiterhelfen.
Vielen Dank schonmal!
ich bin ein wenig am Verzweifeln mit diesem Codestück.
Java:
Connection con = cpds.getConnection(); //get connection from c3p0
String sql = "INSERT INTO `Music` ( " +
"`id` , " +
"`url` , " +
"`artist` , " +
"`title` ," +
"`filename` , " +
"`length` " +
") " +
"VALUES ( NULL , ? , ? , ? , ? , ? )";
PreparedStatement query = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); //java.sql.PreparedStatement
query.setString(1, "http://aswdf.mp3");
query.setString(2, "a");
query.setString(3, "b");
query.setString(4, "c");
query.setInt(5, 5);
query.execute(sql,Statement.RETURN_GENERATED_KEYS);
die Variable sql sieht vor dem execute so aus:
SQL:
INSERT INTO `Music` ( `id` , `url` , `artist` , `title` ,`filename` , `length` ) VALUES ( NULL , ? , ? , ? , ? , ? )
SQL:
mysql> PREPARE stmt1 FROM 'INSERT INTO `Music` ( `id` , `url` , `artist` , `title` ,`filename` , `length` ) VALUES ( NULL , ? , ? , ? , ? , ? )';
Query OK, 0 rows affected (0.02 sec)
Statement prepared
mysql> SET @a = 'a';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @b = 'b';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @c = 'c';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @d = 'd';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @e = 5;
Query OK, 0 rows affected (0.00 sec)
mysql> execute stmt1 using @a,@b,@c,@d,@e;
Query OK, 1 row affected (0.00 sec)
mysql>
Wenn ich das erste Codestück allerdings ausführe bekomme ich diesen Fehler:
Code:
INFO C3P0Registry - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
DEBUG DynamicPooledDataSourceManagerMBean - MBean: com.mchange.v2.c3p0:type=PooledDataSource[z8kfsx8k1p3qwag40lsc|9f671b] registered.
DEBUG BasicResourcePool - incremented pending_acquires: 1
DEBUG BasicResourcePool - incremented pending_acquires: 2
DEBUG BasicResourcePool - incremented pending_acquires: 3
DEBUG BasicResourcePool - com.mchange.v2.resourcepool.BasicResourcePool@618d26 config: [start -> 3; min -> 3; max -> 15; inc -> 3; num_acq_attempts -> 30; acq_attempt_delay -> 1000; check_idle_resources_delay -> 0; mox_resource_age -> 0; max_idle_time -> 0; excess_max_idle_time -> 0; destroy_unreturned_resc_time -> 0; expiration_enforcement_delay -> 0; break_on_acquisition_failure -> false; debug_store_checkout_exceptions -> false]
INFO AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> Bot, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kfsx8k1p3qwag40lsc|9f671b, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://daniel-hlawatsch.de:3306/transformice, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
DEBUG BasicResourcePool - acquire test -- pool size: 0; target_pool_size: 3; desired target? 1
DEBUG BasicResourcePool - awaitAvailable(): [unknown]
DEBUG BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@618d26 [managed: 0, unused: 0, excluded: 0]
DEBUG C3P0PooledConnectionPool - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@9d6065.acquireResource() returning.
DEBUG C3P0PooledConnectionPool - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@9d6065.acquireResource() returning.
DEBUG C3P0PooledConnectionPool - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@9d6065.acquireResource() returning.
DEBUG BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@618d26 [managed: 1, unused: 1, excluded: 0]
DEBUG BasicResourcePool - decremented pending_acquires: 2
DEBUG BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@618d26 [managed: 2, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@14b5f4a)
DEBUG BasicResourcePool - decremented pending_acquires: 1
DEBUG BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@618d26 [managed: 2, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@14b5f4a)
DEBUG BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@618d26 [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@14b5f4a)
DEBUG BasicResourcePool - decremented pending_acquires: 0
DEBUG NewPooledConnection - com.mchange.v2.c3p0.impl.NewPooledConnection@15d17d7 handling a throwable.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? , ? , ? , ? , ? )' at line 1
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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:842)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:948)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:1908)
at de.danley.bottest.Bot.<init>(Bot.java:99)
at de.danley.bottest.Bot.main(Bot.java:57)
DEBUG SqlUtils - Attempted to convert SQLException to SQLException. Leaving it alone. [SQLState: 42000; errorCode: 1064]
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? , ? , ? , ? , ? )' at line 1
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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:842)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:948)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:1908)
at de.danley.bottest.Bot.<init>(Bot.java:99)
at de.danley.bottest.Bot.main(Bot.java:57)
DEBUG DefaultConnectionTester - Testing a Connection in response to an Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? , ? , ? , ? , ? )' at line 1
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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:842)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:948)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:1908)
at de.danley.bottest.Bot.<init>(Bot.java:99)
at de.danley.bottest.Bot.main(Bot.java:57)
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? , ? , ? , ? , ? )' at line 1
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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:842)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:948)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:1908)
at de.danley.bottest.Bot.<init>(Bot.java:99)
at de.danley.bottest.Bot.main(Bot.java:57)
Der Treiber ist "com.mysql.jdbc.Driver" und wird c3p0 übergeben.
Ich bin ein völlig ratlos im Moment. Vielleicht hatte hier ja schon jemand das Problem und kann mir weiterhelfen.
Vielen Dank schonmal!