I am trying to add /edit records in an embedded database.
I have written some code that I think might work, but I would like a second set of eyes to look at to see if it is coded correctly.....
private void Save_Item___MouseClicked(java.awt.event.MouseEvent evt) {
if ("Equipment - Mundane".equals(jComboBox1.getSelectedItem().toString())) {
try {
Connection conn = DriverManager.getConnection("jdbc:derby:Databases/Equipment_Mundane");
Statement stmt = conn.createStatement();
String sql = "INSERT INTO EQUIPMENT_MUNDANE (ITEM_NAME, COST, COIN, WEIGHT) "
+ "VALUES ("
+ "Item_Name.getText(), "
+ "Cost.getText(), "
+ "Coin.getSelectedValue, "
+ "Weight.getText())";
String sql1 = "UPDATE EQUIPMENT_MUNDANE SET ITEM_NAME = Item_Name.getText() "
+ "WHERE ITEM_NAME = Item_Name.getText() AND"
+ "String COST = Cost.getText() AND "
+ "String COIN = Coin.getSelectedValue.toString() AND "
+ "String WEIGHT = Weight.getText()";
if (New_Item.isSelected())
stmt.executeUpdate(sql);
if (Existing_Item.isSelected())
stmt.executeUpdate(sql1);
} catch (SQLException ex) {
Logger.getLogger(Edit_Equip_Databases.class.getName()).log(Level.SEVERE, null, ex);
There are no apparent syntax errors.
The varibles Item_Name, Cost, and Weight are jtextfields, Coin is a jcombobox, and New_Item & Existing_Item are radio buttons.
the statement sql is to add a new record to the database
while sql1 is to change/edit values of an existing record.
I may add a delete record option to the mix.
I would prefer that new records be inserted in alphabetically order per Item_Name, but I know that this code will not do that.
So if you guys will take a look at this and make any suggestions, I would appriciate it.... Dont want to screw up my database accidently.