I have an issue with accessing a table in my database after using the truncate command on it. Having to delete the whole database and recreate it not every time but often. The table is used to hold the index of a card and the card's value.
This is the truncate code:
try {
con = DriverManager.getConnection(host, uName, uPass);
Clean = con.createStatement();
Clean.executeUpdate("TRUNCATE cards");
Clean.close();
} catch (SQLException err) {
System.out.println(err.getMessage());
}
This is the update code:
Set<Integer> generated = new LinkedHashSet<Integer>();
while (generated.size() < Deck.length) {
Integer index = rand.nextInt(Deck.length) + 1;
// As we're adding to a set, this will automatically do a containment check
generated.add(index);
}
//Write card index to database
Iterator itr = generated.iterator();
try {
con = DriverManager.getConnection(host, uName, uPass);
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String SQL = "SELECT * FROM cards";
while (itr.hasNext()) {
int thisCard = ((int)itr.next()-1)%52;//Makes sure card is a value between 1 and 52
int thisVal = (thisCard)%13;//Writes a value of 1 to 13 in the datbase associated with thisCard
rs = stmt.executeQuery(SQL);
rs.moveToInsertRow();
rs.updateInt("CardIndex", thisCard +1);//(int) itr.next());
rs.updateInt("CardValue", thisVal +1);
rs.insertRow();
}
stmt.close();
rs.close();
} catch (SQLException err) {
System.out.println(err.getMessage());
}
generated.clear();
Any Ideas? I tried the delete command but the auto increment started at like 400 and I need it to start at 1 evrytime. That is why I truncate.