Hallo Programmierer,
Als erstens wünsche ich euch einen schönen Abend und möchte nun meine Frage stellen. Wenn ihr ganz runterscrollt seht ihr eine Fehlerausgabe (Exception). Ich habe eine kleine Oberfläche, da kann ich Kategorie erstellen, durch Eingabe in die Textfelder sollte ich per ADD-Button die Daten in die Datenbank speichern können. Leider bekomme ich eine "Unexpected token", was bedeutet das...
In der CategoryController rufe ich per
die Methode auf, habe irgendwo eine kleine/einfache Fehler, deshalb Anfängerfrage
Wie kann ich es lösen, damit Insert problemlos funzt?
danke im voraus
CategoryController - Controller Klasse für Kategorieverwaltung
Ausgabe + Exception:
danke danke
Als erstens wünsche ich euch einen schönen Abend und möchte nun meine Frage stellen. Wenn ihr ganz runterscrollt seht ihr eine Fehlerausgabe (Exception). Ich habe eine kleine Oberfläche, da kann ich Kategorie erstellen, durch Eingabe in die Textfelder sollte ich per ADD-Button die Daten in die Datenbank speichern können. Leider bekomme ich eine "Unexpected token", was bedeutet das...
In der CategoryController rufe ich per
Code:
dbconn.addCategory(cat_name,cat_descr);
Wie kann ich es lösen, damit Insert problemlos funzt?
danke im voraus
CategoryController - Controller Klasse für Kategorieverwaltung
Code:
import database.Testdb;
public class CategoryController implements ActionListener {
private Testdb dbconn;
private CategoryDialog cat_dialog;
public CategoryController(final CategoryDialog cat_dialog)
{
this.cat_dialog = cat_dialog;
ActionListener AddCategoryListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String cat_name = cat_dialog.getCatName();
String cat_descr = cat_dialog.getCatDescr();
System.out.println("Ausgabe cname: " + cat_name);
System.out.println("Ausgabe cdescr: " + cat_descr);
dbconn.addCategory(cat_name,cat_descr);
}
};
cat_dialog.bt_addCategoryDialogActionPerformed(AddCategoryListener);
}
public void actionPerformed(ActionEvent e) {
//LEER
}
}
Code:
Testdb:
public class Testdb {
Connection conn; //our connnection to the db - presist for life of program
static Testdb db = null;
...
//use for SQL commands CREATE, DROP, INSERT and UPDATE
public synchronized void update(String expression) throws SQLException {
Statement st = null;
st = conn.createStatement(); // statements
int i = st.executeUpdate(expression); // run the query
if (i == -1) {
System.out.println("db error : " + expression);
}
st.close();
} // void update()
public static void addCategory(String cname, String cdescr) {
try {
db = new Testdb();
} catch (Exception ex1) {
ex1.printStackTrace(); // could not start db
return; // bye bye
}
try {
db.update("INSERT INTO category VALUES(50, '"+cname+"','"+cdescr+"'");
db.query("SELECT * FROM category WHERE cat_id");
db.shutdown();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} // class Testdb
Ausgabe + Exception:
Code:
Ausgabe cname: asdf
Ausgabe cdescr: asdf
java.sql.SQLException: Unexpected token: in statement [INSERT INTO category VALUES(50, 'asdf','asdf']
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.executeUpdate(Unknown Source)
at database.Testdb.update(Testdb.java:117)
at database.Testdb.addCategory(Testdb.java:217)
at contactManager.CategoryController$1.actionPerformed(CategoryController.java:29)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
danke danke