PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : preparedStatement ausgeben


Zarathustra
2004-11-23, 12:59:23
Das basiert ja auf einem String, der mit der erzeugenden Methode des Connectors z.B. übergeben wird, und dann im weiteren Verlauf des Programms "ergänzt" wird.

Ich brauche nun dringend eine Möglichkeit, das Ergebnis, also den fertigen SQL-Befehl in der Konsole auszugeben... :|

Danke schonmal für jede Antwort.

EDIT: Wie vielleicht schon klar ist geht es um Java. :D

noid
2004-11-23, 14:01:17
.toString() ?

Zarathustra
2004-11-23, 14:11:25
Ja das wäre schön, aber wenn's das schon wäre, wäre ich schon vor einigen Stunden fertig geworden. :frown:

aus
System.out.println("*** executeUpdate : " + pStmt.toString());

wird
*** executeUpdate : org.apache.commons.dbcp.DelegatingPreparedStatement@883644

Das ist übrigens bei
System.out.println("*** executeUpdate : " + pStmt);
genauso.

Btw die ist gar nicht in der API...

HellHorse
2004-11-23, 14:30:00
Eigentlich sollten PreparedStatements vom DBMS vorkompiliert werden. Es werden dann lediglich "Daten eingefügt".
Wie das query "wirklich" aussieht, ist von DBMS zu DBMS verschieden und wird dir wohl nicht viel helfen.
Du kannst aber mit dem Debugger den String abfangen, den du benutzt, um das Query zu erstellen und dann natürlich die setXXX methoden um die Daten zu setzen.

noid
2004-11-23, 14:31:12
wie wärs damit? ;)

http://archives.postgresql.org/pgsql-jdbc/2001-03/msg00110.php

Zarathustra
2004-11-23, 14:59:57
Ich suche seit 2 Tagen einen Fehler, der offenbar beim Ausführen eines PreparedStatements entsteht, allerdings nichts bewirkt, ausser, dass der SQL-Befehl nicht ausgeführt wird. Er wird im laufe von fast 600 Zeilen code zusammengesetzt, aus Komponenten, die durch exzessiven Struts *autsch* -Einsatz ermittelt werden. Und ich möchte nun wissen, ob das richtige dabei herauskommt. :rolleyes:

@noid: das ist schon ziemlich gut :) , nur die StringUtil-Klasse mit der Methode "StringUtil.countOccurances(sql, "?")" ist nirgends zu finden. Hast du die zufällig?
...static StringUtil function that simply counts the '?'s in the query...

ethrandil
2004-11-23, 15:50:13
Fragst du denn nach dem Query die Fehler-Nummer und -Beschreibung ab?

- Eth

HellHorse
2004-11-23, 16:17:50
wie wärs damit? ;)

http://archives.postgresql.org/pgsql-jdbc/2001-03/msg00110.php
Nett, gibt zwar das originale statement und die Paramter aus ersetzt die ? aber nicht, und es kompiliert nicht weil vieles fehlt. Das könnte hinhauen:

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;

/**
* a wrapper class for prepared statments to allow them to be logged original
* code from <a
* href="http://archives.postgresql.org/pgsql-jdbc/2001-03/msg00110.php>http://archives.postgresql.org/pgsql-jdbc/2001-03/msg00110.php
* </a>
*/
public class PreparedStatementLogable implements PreparedStatement {
PreparedStatement stmt;

String sql;

String[] params;

public PreparedStatementLogable(Connection con, String sql)
throws SQLException {
this.stmt = con.prepareStatement(sql);
this.sql = sql;
params = new String[countOccurances(sql, "?")];
}

private static int countOccurances(String string, String subString) {
int currentIndex = string.indexOf(subString);
int occurances = 0;
while (currentIndex > 0) {
currentIndex = string.indexOf(subString);
occurances += 1;
}
return occurances;
}

public String toString() {
StringBuilder buff = new StringBuilder(sql);
int currentIndex = 0;
for (String nextParam : params) {
currentIndex = buff.indexOf("?", currentIndex);
buff.replace(currentIndex, currentIndex + 1, nextParam);
}
return buff.toString();
}

/** ***************************************************************************** */
/***************************************************************************
* implement PreparedStatement /
**************************************************************************/
public ResultSet executeQuery() throws SQLException {
return stmt.executeQuery();
}

public int executeUpdate() throws SQLException {
return stmt.executeUpdate();
}

public void setNull(int parameterIndex, int sqlType) throws SQLException {
params[parameterIndex - 1] = null;
stmt.setNull(parameterIndex, sqlType);
}

public void setBoolean(int parameterIndex, boolean x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setBoolean(parameterIndex, x);
}

public void setByte(int parameterIndex, byte x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setByte(parameterIndex, x);
}

public void setShort(int parameterIndex, short x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setShort(parameterIndex, x);
}

public void setInt(int parameterIndex, int x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setInt(parameterIndex, x);
}

public void setLong(int parameterIndex, long x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setLong(parameterIndex, x);
}

public void setFloat(int parameterIndex, float x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setFloat(parameterIndex, x);
}

public void setDouble(int parameterIndex, double x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setDouble(parameterIndex, x);
}

public void setBigDecimal(int parameterIndex, BigDecimal x)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setBigDecimal(parameterIndex, x);
}

public void setString(int parameterIndex, String x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setString(parameterIndex, x);
}

public void setBytes(int parameterIndex, byte[] x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setBytes(parameterIndex, x);
}

public void setDate(int parameterIndex, java.sql.Date x)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setDate(parameterIndex, x);
}

public void setTime(int parameterIndex, Time x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setTime(parameterIndex, x);
}

public void setTimestamp(int parameterIndex, Timestamp x)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setTimestamp(parameterIndex, x);
}

public void setAsciiStream(int parameterIndex, InputStream x, int length)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setAsciiStream(parameterIndex, x, length);
}

@Deprecated public void setUnicodeStream(int parameterIndex, InputStream x,
int length) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setUnicodeStream(parameterIndex, x, length);
}

public void setBinaryStream(int parameterIndex, InputStream x, int length)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setBinaryStream(parameterIndex, x, length);
}

public void clearParameters() throws SQLException {
params = new String[params.length];
stmt.clearParameters();
}

public void setObject(int parameterIndex, Object x, int targetSqlType,
int scale) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setObject(parameterIndex, x, targetSqlType, scale);
}

public void setObject(int parameterIndex, Object x, int targetSqlType)
throws SQLException {
params[parameterIndex - 1] = "" + x;
stmt.setObject(parameterIndex, x, targetSqlType);
}

public void setObject(int parameterIndex, Object x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setObject(parameterIndex, x);
}

public boolean execute() throws SQLException {
return stmt.execute();
}

public void addBatch() throws SQLException {
stmt.addBatch();
}

public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException {
params[parameterIndex - 1] = reader.toString();
stmt.setCharacterStream(parameterIndex, reader, length);
}

public void setRef(int i, Ref x) throws SQLException {
params[i - 1] = String.valueOf(x);
stmt.setRef(i, x);
}

public void setBlob(int i, Blob x) throws SQLException {
params[i - 1] = String.valueOf(x);
stmt.setBlob(i, x);
}

public void setClob(int i, Clob x) throws SQLException {
params[i - 1] = String.valueOf(x);
stmt.setClob(i, x);
}

public void setArray(int i, Array x) throws SQLException {
params[i - 1] = String.valueOf(x);
stmt.setArray(i, x);
}

public ResultSetMetaData getMetaData() throws SQLException {
return stmt.getMetaData();
}

public void setDate(int parameterIndex, Date x, Calendar cal)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setDate(parameterIndex, x, cal);
}

public void setTime(int parameterIndex, Time x, Calendar cal)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setTime(parameterIndex, x, cal);
}

public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setTimestamp(parameterIndex, x, cal);
}

public void setURL(int parameterIndex, URL x) throws SQLException {
params[parameterIndex - 1] = String.valueOf(x);
stmt.setURL(parameterIndex, x);
}

public void setNull(int paramIndex, int sqlType, String typeName)
throws SQLException {
params[paramIndex - 1] = null;
stmt.setNull(paramIndex, sqlType, typeName);
}

public ResultSet executeQuery(String sql) throws SQLException {
return stmt.executeQuery(sql);
}

public int executeUpdate(String sql) throws SQLException {
return stmt.executeUpdate(sql);
}

public void close() throws SQLException {
stmt.close();
}

public int getMaxFieldSize() throws SQLException {
return stmt.getMaxFieldSize();
}

public void setMaxFieldSize(int max) throws SQLException {
stmt.setMaxFieldSize(max);
}

public int getMaxRows() throws SQLException {
return stmt.getMaxRows();
}

public void setMaxRows(int max) throws SQLException {
stmt.setMaxRows(max);
}

public void setEscapeProcessing(boolean enable) throws SQLException {
stmt.setEscapeProcessing(enable);
}

public int getQueryTimeout() throws SQLException {
return stmt.getQueryTimeout();
}

public void setQueryTimeout(int seconds) throws SQLException {
stmt.setQueryTimeout(seconds);
}

public void cancel() throws SQLException {
stmt.cancel();
}

public SQLWarning getWarnings() throws SQLException {
return stmt.getWarnings();
}

public void clearWarnings() throws SQLException {
stmt.clearWarnings();
}

public void setCursorName(String name) throws SQLException {
stmt.setCursorName(name);
}

public boolean execute(String sql) throws SQLException {
return stmt.execute(sql);
}

public ResultSet getResultSet() throws SQLException {
return stmt.getResultSet();
}

public int getUpdateCount() throws SQLException {
return stmt.getUpdateCount();
}

public boolean getMoreResults() throws SQLException {
return stmt.getMoreResults();
}

public void setFetchDirection(int direction) throws SQLException {
stmt.setFetchDirection(direction);
}

public int getFetchDirection() throws SQLException {
return stmt.getFetchDirection();
}

public void setFetchSize(int rows) throws SQLException {
stmt.setFetchSize(rows);
}

public int getFetchSize() throws SQLException {
return stmt.getFetchSize();
}

public int getResultSetConcurrency() throws SQLException {
return stmt.getResultSetConcurrency();
}

public int getResultSetType() throws SQLException {
return stmt.getResultSetType();
}

public void addBatch(String sql) throws SQLException {
stmt.addBatch(sql);
}

public void clearBatch() throws SQLException {
stmt.clearBatch();
}

public int[] executeBatch() throws SQLException {
return stmt.executeBatch();
}

public Connection getConnection() throws SQLException {
return stmt.getConnection();
}

public ParameterMetaData getParameterMetaData() throws SQLException {
return stmt.getParameterMetaData();
}

public boolean execute(String sql, int autoGeneratedKeys)
throws SQLException {
return stmt.execute(sql, autoGeneratedKeys);
}

public boolean execute(String sql, int[] columnIndexes) throws SQLException {
return stmt.execute(sql, columnIndexes);
}

public boolean execute(String sql, String[] columnNames)
throws SQLException {
return stmt.execute(sql, columnNames);
}

public int executeUpdate(String sql, int autoGeneratedKeys)
throws SQLException {
return stmt.executeUpdate(sql, autoGeneratedKeys);
}

public int executeUpdate(String sql, int[] columnIndexes)
throws SQLException {
return stmt.executeUpdate(sql, columnIndexes);
}

public int executeUpdate(String sql, String[] columnNames)
throws SQLException {
return stmt.executeUpdate(sql, columnNames);
}

public ResultSet getGeneratedKeys() throws SQLException {
return stmt.getGeneratedKeys();
}

public boolean getMoreResults(int current) throws SQLException {
return stmt.getMoreResults(current);
}

public int getResultSetHoldability() throws SQLException {
return stmt.getResultSetHoldability();
}
}

Ist natürlich nicht getested. ;)

Edit:
StringUtil.countOccurances ist auch gefixt

Zarathustra
2004-11-24, 09:15:19
Danke! Ich werds testen...

Probleme:
@Deprecated public void setUnicodeStream(...)
-> "Syntax error on token(s)" bei @Deprecated

public String toString(){... for (String nextParam : params) {...} ...}
-> "Syntax error on token(s), misplaced construct(s)" bei dem for()-Teil,
-> "Syntax error on token ")", : expected"

Und woher kommt der "StringBuilder"?
"StringBuilder buff = new StringBuilder(sql);"
Oder hätte das "StringBuffer" heissen sollen?

EDIT: Ich benutze hier Eclipse 3.

Und: Ich verstehe die Stelle nicht, was bedeutet die komische schreibweise der for-Schleife...?

@ETH: meinst du die Fehlerausgaben der Datenbank? Ja, die werden empfangen, aber da kommt offenbar auch nix. :confused:

EDIT2:
Ok, deprecated muss in den Kommentar /**...*/. Verstehe.

EDIT3:
Ich glaube in countOccurances() ist eine Endlosschleife...

ethrandil
2004-11-25, 22:42:27
Olà

Probleme:

public String toString(){... for (String nextParam : params) {...} ...}
-> "Syntax error on token(s), misplaced construct(s)" bei dem for()-Teil,
-> "Syntax error on token ")", : expected"

Und woher kommt der "StringBuilder"?
"StringBuilder buff = new StringBuilder(sql);"
Oder hätte das "StringBuffer" heissen sollen?

Unser Höllenpferd setzt auf Java 5.0 (1.5), darum kannst du die Forschleife so nicht unter älteren SDKs einsetzen.


for (String nextParam : params) {
currentIndex = buff.indexOf("?", currentIndex);
buff.replace(currentIndex, currentIndex + 1, nextParam);
}
//IDENTISCH ZU

for (int i=0; i<params.length; String nextParam = params[i]) {
currentIndex = buff.indexOf("?", i);
buff.replace(i, i + 1, nextParam);
}


Hilft das?

- Eth

Zarathustra
2004-11-30, 15:18:37
Danke eth! :)

Ich hatte in den letzten Tagen zu viel anderes zu tun, deshalb die späte Antwort.
Aber ein Problem ist da noch...

Ich glaube in countOccurances() ist eine Endlosschleife...
...und die verendet immer bei 71.

Hier der sql_str:

INSERT INTO PRODUKTE (AW_ID,PRODUKTNAME,BESCHREIBUNG,PSP_ELEMENT,VERTRAG_ID,LAUFZEIT_VON,LAUFZEIT_BIS ,KUENDIGUNG,ERINNERUNG,VERANTWORTLICHER,VERLAENGERUNG,V_EINHEIT,GEGENSTAND,LEIST UNG,HARDWARE,HW_ABGRENZUNG,SOFTWARE,SW_ABGRENZUNG,SYSTEMBETREUUNG,ANWENDUNGSBETR EUUNG,HELPDESK,BETREU_ABGRENZUNG,ABRECHNUNG,SONSTIGES,VERSION,STATUS_ID,ZEIT) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)


EDIT:

while (currentIndex > 0 && currentIndex <= string.length()) {
currentIndex = string.indexOf(subString, currentIndex+1);
occurances += 1;
System.out.println("countOccurances.currentIndex: " + currentIndex);
}


Jetzt scheints zu gehen erstmal...

aber toString() bleibt stecken! :uwoot:

HellHorse
2004-11-30, 16:37:31
EDIT3:
Ich glaube in countOccurances() ist eine Endlosschleife...
Stimmt leider :(
So sollte es gehen

private static int countOccurances(String string, String subString) {
int currentIndex = string.indexOf(subString);
int occurances = 0;
while (currentIndex >= 0) {
currentIndex = string.indexOf(subString, currentIndex + 1);
occurances += 1;
}
return occurances;
}


aber toString() bleibt stecken!
eth hat das increment vergessen :ugly2:

Zarathustra
2004-12-01, 09:40:20
eth hat das increment vergessen :ugly2:

Wo jetzt?

HellHorse
2004-12-01, 12:16:09
Wo jetzt?
In toString natürlich.

Zarathustra
2004-12-01, 12:48:58
In toString natürlich. :biggrin:

Und wo in toString() soll es hin? Meinst du "i++" mit in die for-Schleife?

Hmm er gibt es aus, nun bleiben aber die Fragezeichen erhalten! :uwoot:


aaalso:
aus
insertVersion: INSERT INTO PRODUKTE_VERLAUF (PRODUKT_ID,VERSION,ELEMENT,WERT) VALUES (?,?,?,?) Sorry, war oben falsch!

wird
->Statement: N01GEGENSTANDT INTO PRODUKTE_VERLAUF (PRODUKT_ID,VERSION,ELEMENT,WERT) VALUES (?,?,?,?)

durch

try {
for(int i=0; i<elemente.size(); i++)
{
// Java-PreparedStatement erzeugen
pStmt = new PreparedStatementLogable(conn, sql_str);
//pStmt = conn.prepareStatement(sql_str);

//PreparedStatement mit aktuellen Produkt-Daten füllen
this.setIntWithNull(pStmt, 1, produkt.getProdukt_id());
this.setIntWithNull(pStmt, 2, neueVersion);
pStmt.setString(3, (String)elemente.get(i));
pStmt.setString(4, (String)werte.get(i));
System.out.println("elemente.get("+i+")" + (String)elemente.get(i));
System.out.println("werte.get("+i+")" + (String)werte.get(i));
System.out.println("insertVersion: " + sql_str);
System.out.println("->Statement: " + pStmt.toString());

// UPDATE ausführen
rowCount = pStmt.executeUpdate();
}
}
catch (SQLException exc) {
// Fehler in Log-Datei schreiben
if (log.isErrorEnabled()) {
log.error(
Utils.buildLogMsgWithExcCause(DBTabelle.ERROR_UPDATE, exc) );
}


mit dem Kommentar:
countOccurances.currentIndex: 73
countOccurances.currentIndex: 75
countOccurances.currentIndex: 77
countOccurances.currentIndex: -1 //hä???


, was mir unerklärlich ist: GEGENSTAND ist eine String-Variable, deren Inhalt mit "elemente.add(GEGENSTAND);" eingefügt wird... :confused:

HellHorse
2004-12-01, 17:27:46
Und wo in toString() soll es hin? Meinst du "i++" mit in die for-Schleife?

Ja. Du musst halt schauen, dass du den index auch inkrementierest, so du dass du über das Array iterierst und mal die Abbruchsbedinungung erreichst.

Ich bin mir ziemlich sicher, dass folgender Code hinhaut:

public static int countOccurances(String string, String subString) {
int currentIndex = string.indexOf(subString);
int occurances = 0;
while (currentIndex >= 0) {
currentIndex = string.indexOf(subString, currentIndex + 1);
occurances += 1;
}
return occurances;
}

public static String insert(String s, String r, String[] elements) {
StringBuilder buff = new StringBuilder(s);
int currentIndex = 0;
for (String nextElement : elements) {
currentIndex = buff.indexOf(r, currentIndex);
buff.replace(currentIndex, currentIndex + r.length(), nextElement);
}
return buff.toString();
}

public String toString() {
return insert(sql, "?", params);
}

Ist eigentlich der gleiche wie vorher bloss testbar.
Ok die Variablennamen sind scheisse, aber wie heisst es so schön? "left as an exercise to the user" X-D

Wie komme ich dazu?

public class HelperMethodTest extends TestCase {

public void testSingleChar() {
assertEquals(0, PreparedStatementLogable.countOccurances("SELECT name FROM users where clue > 0", "?"));
assertEquals(3, PreparedStatementLogable.countOccurances("SELECT ? FROM ? where ?", "?"));
assertEquals(2, PreparedStatementLogable.countOccurances("SELECT ? FROM ? where", "?"));
assertEquals(4, PreparedStatementLogable.countOccurances("? SELECT ? FROM ? where ?", "?"));
assertEquals(5, PreparedStatementLogable.countOccurances("?? SELECT ? FROM ? where ?", "?"));
}

public void testMulitpleChars() {
assertEquals(3, PreparedStatementLogable.countOccurances("SELECT <a> FROM <a> where <a>", "<a>"));
assertEquals(2, PreparedStatementLogable.countOccurances("SELECT <a> FROM <a> where", "<a>"));
assertEquals(4, PreparedStatementLogable.countOccurances("<a> SELECT <a> FROM <a> where <a>", "<a>"));
assertEquals(5, PreparedStatementLogable.countOccurances("<a><a> SELECT <a> FROM <a> where <a>", "<a>"));
}

public void testInsert() {
assertEquals("INSERT INTO users(name, password) VALUES (me,secret);", PreparedStatementLogable.insert("INSERT INTO users(name, password) VALUES (?,?);" , "?", new String[] {"me", "secret"}));
assertEquals("INSERT INTO users(name, password) VALUES (me,secret);", PreparedStatementLogable.insert("INSERT INTO users(name, password) VALUES (XXX,XXX);" , "XXX", new String[] {"me", "secret"}));
assertEquals("HELLOCRUELWORLD", PreparedStatementLogable.insert("<a><a><a>" , "<a>", new String[] {"HELLO","CRUEL","WORLD"}));
}
}

Zarathustra
2004-12-02, 10:21:23
Hmm es ändert sich nichts...

Ich glaube das Problem ist, dass ich nicht die StringBuilder-Klasse habe,
ich benutze Java 1.4.2 .
:uconf3:

HellHorse
2004-12-02, 14:00:00
Ich glaube das Problem ist, dass ich nicht die StringBuilder-Klasse habe,

Nimmst du StringBuffer und iterierst "normal" über das String array.

Zarathustra
2004-12-02, 14:18:46
Nimmst du StringBuffer und iterierst "normal" über das String array.


Mach ich doch. :|
Hier der ganze Code wie ich ihn jetzt habe:

public PreparedStatementLogable(Connection con, String sql)
throws SQLException {
this.stmt = con.prepareStatement(sql);
this.sql = sql;
params = new String[countOccurances(sql, "?")];
}


public static int countOccurances(String string, String subString) {
int currentIndex = string.indexOf(subString);
int occurances = 0;
while (currentIndex >= 0) {
currentIndex = string.indexOf(subString, currentIndex + 1);
System.out.println("currentIndex: " + currentIndex);
occurances += 1;
}
System.out.println("occurances: " + occurances);
return occurances;
}

public static String insert(String s, String r, String[] elements) {
StringBuffer buff = new StringBuffer(s);
int currentIndex = 0;
String nextElement = new String();
for (int i=0; i<elements.length; nextElement = elements[i], i++) {
currentIndex = buff.indexOf(r, i);
buff.replace(i, i + 1, nextElement);
}

/*
for (int i=0; i<params.length; String nextParam = params[i]) {
currentIndex = buff.indexOf(r, i);
buff.replace(i, i + 1, nextParam);
}*/
return buff.toString();
}

public String toString() {
return insert(sql, "?", params);
}


Aber die Ausgaben bleiben wie oben, mit dem "GEGENSTAND" drin und die Fragezeichen sind auch noch da. So ein Mist, und es gibt keine Stelle in der das mit dem "GEGENSTAND" passieren könnte. Warum zum Teufel klappt das nicht?
Was nun?

HellHorse
2004-12-02, 19:14:33
Mach ich doch. :|

String nextElement = new String();
for (int i=0; i<elements.length; nextElement = elements[i], i++) {


Sorry, aber das is sicher nicht der der korrekte Weg über ein Array von Strings zu iterieren.


currentIndex = buff.indexOf(r, i);
buff.replace(i, i + 1, nextElement);


Falscher Index, i ist der Index für des aktuellen Array elementes und nicht der offset um den Startindex des nächsten Substrings zu suchen.

Zarathustra
2004-12-03, 08:52:09
Da hab ich micht wohl von eth verwirren lassen (sry eth ;) )...


for (int i=0; i<elements.length; nextElement = elements[i], i++) {
currentIndex = buff.indexOf(r, currentIndex + 1);
buff.replace(currentIndex, currentIndex + r.length(), nextElement);
}

Jetzt gehts!

->Statement: INSERT INTO PRODUKTE_VERLAUF (PRODUKT_ID,VERSION,ELEMENT,WERT) VALUES (,0,1,GEGENSTAND)

jetzt weiss ich auch warum er es nicht ausführt, die erste ID fehlt...


Ich danke allen beteiligten vielmals für ihre Hilfe! ;D

stefan42
2004-12-03, 20:06:02
Wie wär's denn mit dem P6Spy, würde der Dir helfen?
http://www.p6spy.com/

ethrandil
2004-12-03, 21:14:11
:whistle:

ja, tut mir leid, ich hab das doch glatt übersehn...

- Eth