I'm creating a program where I should save data on database. I have two frames but only using one table in one database and on the first frame I already saved data on row 1-6. Now on the second frame I want to add data on row 7-12 only. How can I do this? Or should I make another table instead?
I'm newbie to Java, so help would be great.
Here's my code for the save:
JOptionPane.showMessageDialog(this, "Save this input?", "Confirm", JOptionPane.QUESTION_MESSAGE);
strCountry = txtCountry.getText();
strMembers = txtareaMembers.getText();
strSong = txtSong.getText();
strAlbum = txtAlbum.getText();
Concert = (String) cmbConcerts.getSelectedItem();
Biblio = (String) cmbBiblio.getSelectedItem();
btnSubFirst.setEnabled(false);
btnSubPrev.setEnabled(false);
btnSubNext.setEnabled(true);
btnSubLast.setEnabled(true);
btnSubEdit.setEnabled(false);
btnSubSave.setEnabled(false);
btnSubCancel.setEnabled(true);
txtCountry.setEditable(false);
txtSong.setEditable(false);
txtAlbum.setEditable(false);
SaveData();
public void SaveData() {
try {
String strQuery = "INSERT INTO tblband(bandname,label,genre,year,member,album,country,members,song,recent,concert,biblio)" + "VALUES" + "(?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement st = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/banddb", "root", "");
st = con.prepareStatement(strQuery);
st.setString(1, strBand);
st.setString(2, strRecord);
st.setString(3, Genre);
st.setString(4, Year);
st.setString(5, Member);
st.setString(6, Album);
st.setString(7, strCountry);
st.setString(8, strSong);
st.setString(9, strAlbum);
st.setString(10, Concert);
st.setString(11, Biblio);
st.setString(12, strMembers);
st.executeUpdate();
con.close();
JOptionPane.showMessageDialog(null, "Data is successfully inserted into database.");
} catch(Exception e) {
JOptionPane.showMessageDialog(null, "Error in submitting data." + e);
}
}