MySQL PreparedStatement mit c3p0 schlägt fehl. Warum?

danley

Mitglied
Hallo,

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 , ? , ? , ? , ? , ? )
Und funktioniert auch auf meinem MySQL system auf der Commandozeile:

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!
 
M

maki

Gast
NULL als ID ist keine so gute Idee, lass die ID doch komplett weg wenn sie dir von der DB erstellt wird.
 

danley

Mitglied
Hallo,

danke für die Hilfe. Ohne parameter hat es geklappt. Auf die Idee bin ich gestern vor lauter auf das SQL starren garnicht mehr gekommen.

Die ID ist auch raus.

Also nochmal vielen Dank.

danley
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
Kirby.exe PreparedStatement wird nicht ausgeführt Datenbankprogrammierung 5
V SQLite NullPointerException in preparedStatement.close(); Datenbankprogrammierung 8
Neumi5694 SQL-Statement Preparedstatement - try resource vs. Garbage Collector Datenbankprogrammierung 5
S JDBC PreparedStatement durchiterieren Datenbankprogrammierung 6
S CSV Datein in DB übernehmen:PreparedStatement bzw executeBatch() zu langsam Datenbankprogrammierung 11
P MySQL PreparedStatement vs. StoredProcedure vs. executeBatch Datenbankprogrammierung 1
P PreparedStatement IN-Funktion Datenbankprogrammierung 8
R PreparedStatement ohne Parameter? Datenbankprogrammierung 4
turmaline Oracle [PreparedStatement] Klammer fehlt Datenbankprogrammierung 9
C PreparedStatement und null Datenbankprogrammierung 13
J Problem bei Boolean in PreparedStatement Datenbankprogrammierung 5
M Variable in SQL SELECT * FROM ... WHERE mithilfe von PreparedStatement benutzen? Datenbankprogrammierung 28
S Oracle Problem mit PreparedStatement.setString(1,"str") Datenbankprogrammierung 10
M MySQL preparedStatement und Anführungszeichen Datenbankprogrammierung 6
L MySQL Probleme mit PreparedStatement für SQL-Abfrage in Java Datenbankprogrammierung 2
G PreparedStatement und Transaktionen Datenbankprogrammierung 2
N Leeres Blob in ein PreparedStatement eintragen Datenbankprogrammierung 2
P PreparedStatement batch und getGeneratedKeys Datenbankprogrammierung 7
T MySQL PreparedStatement mit INSERTs langsam, Batch-Statement auch Datenbankprogrammierung 4
B H2 PreparedStatement SELECT * FROM ? Datenbankprogrammierung 4
M FindBugs und PreparedStatement aus einer Datei lesen Datenbankprogrammierung 11
Guybrush Threepwood PreparedStatement: execute() oder executeUpdate() Datenbankprogrammierung 3
R PreparedStatement mit verschiedenen Datenbanken Datenbankprogrammierung 2
R Frage zu PreparedStatement/ResultSet Datenbankprogrammierung 16
R Zugriff auf SQL im PreparedStatement Datenbankprogrammierung 4
W preparedStatement (MySQL - JDBC) Datenbankprogrammierung 5
Landei PreparedStatement Parameter mehrfach verwenden Datenbankprogrammierung 18
S Create Table mit PreparedStatement Datenbankprogrammierung 2
S Select mit PreparedStatement Datenbankprogrammierung 2
S PreparedStatement setArray(int i, java.sql.Array) Datenbankprogrammierung 17
M Preparedstatement SQL-string auslesen Datenbankprogrammierung 13
T PreparedStatement anzeigen Datenbankprogrammierung 10
A PreparedStatement im Servlet - Referenz speichern Datenbankprogrammierung 3
P PreparedStatement - Angabe des PK Datenbankprogrammierung 4
J Fehler beim PreparedStatement Datenbankprogrammierung 2
B PreparedStatement - anzahl ParameterValues Datenbankprogrammierung 6
J PreparedStatement Datenbankprogrammierung 5
C PreparedStatement Datenbankprogrammierung 2
R DB2 PreparedStatement Batches ungültige Reihenfolge Datenbankprogrammierung 4
F Problem mit Hibernate c3p0 Datenbankprogrammierung 2
T Spring MongoDB: Auswertung schlägt fehl Datenbankprogrammierung 1
G PostgreSQL Treiber laden schlägt fehl wegen: "... passwortbasierte Authentifizierung ..." Datenbankprogrammierung 2
S Squirrel - Connect schlägt fehl mit NoClassDefFoundError: sun/io/UnknownCharacterException Datenbankprogrammierung 0
C Derby/JavaDB INSERT auf FOREIGN KEY schlägt fehl Datenbankprogrammierung 2
c_sidi90 JDBC Oracle Connection schlägt fehl Datenbankprogrammierung 2
L MySQL Einträge löschen schlägt fehl Datenbankprogrammierung 2
S MySQL INSERT schlägt nicht fehl, fügt aber auch nichts ein Datenbankprogrammierung 13
A MySQL ResultSet.updateBytes schlägt fehl Datenbankprogrammierung 2
M H2 Laden der H2-Treiber schlägt fehl Datenbankprogrammierung 2
T MySQL: Join auf sich selbst schlägt fehlt Datenbankprogrammierung 3
O HSQLDB Verbindung schlägt fehl Datenbankprogrammierung 3
V [MYSQL] getTimestamp schlägt fehl? Datenbankprogrammierung 3
J Verbindung zur Datenbank schlägt fehl... Datenbankprogrammierung 2
S hibernate-Mapping schlägt fehl Datenbankprogrammierung 8

Ähnliche Java Themen

Neue Themen


Oben