Gentili ragazzi vorrei una info, io effettuo un update su un DB java, per fare in modo che ad aggiornamento eseguito mi restituisca "il record è stato aggiornato" oppure mi generi un eccezione come posso procedere?? mi serve entro le 21 di stasera.
Vi posto il codice da me fatto:
codice:
import java.sql.*;
import java.util.Scanner;
public class UpdateCause {
public static void main(String[] args){
Scanner console=new Scanner(System.in);
int codice = 0;
String stato = "";
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn = DriverManager.getConnection(url,"root","root");
for (SQLWarning warn = conn.getWarnings(); warn != null;warn=warn.getNextWarning()){
System.out.println("SQLWarning:");
System.out.println("State: " + warn.getSQLState());
System.out.println("Message: " + warn.getMessage());
System.out.println("Error Code: " + warn.getErrorCode());
}
Statement stmt = conn.createStatement();
System.out.println("Aggiornamento della causa:\n");
System.out.println("Inserire il codice della causa: ");
codice = Integer.parseInt(console.nextLine());
System.out.println("Inserire lo stato della causa(Positivo|Negativo)");
stato = console.nextLine();
query = "UPDATE causa SET stato = '" + stato + "' WHERE codice ="+ codice;
stmt.executeUpdate(query);
stmt.close();
conn.close();
}
catch(SQLException se){
System.out.println("SQLException:");
while (se != null){
System.out.println("State: " + se.getSQLState());
System.out.println("Message: " + se.getMessage());
System.out.println("Error Code: " + se.getErrorCode());
se = se.getNextException();
}
}
catch(Exception e){
System.out.println(e);
}
}
static final String url = "jdbc:mysql://localhost/studio";
static String query;
}
Spero in un possibile aiuto. grazie mille