import java.sql.*;

public class ModyfikujDane {

    /**
	 * @param args
	 */
    public static void main(String[] args) throws ClassNotFoundException {
        Connection connection = null;
        int ile;
        String[] imiona = { "Ala", "Basia", "Dusia", "Gienia", "Kasia" };
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=KursBD;user=sa;password=sql2005");
            Statement stmt = connection.createStatement();
            ile = stmt.executeUpdate("delete from Names");
            System.out.println("Ilość usuniętych wierszy: " + ile);
            for (int i = 0; i < imiona.length; i++) {
                ile = 
stmt.executeUpdate("insert into Names values(" + (i + 1) + ", '" + imiona[i] + 
                   "')");
                System.out.println("Liczba wstawionych wierszy: " + ile);
            }
            stmt.close();
        } catch (SQLException sqle) {
            sqle.printStackTrace();
            while (sqle != null) {
                String logMessage = 
                    "\n SQL Error: " + sqle.getMessage() + "\n\t\t" + 
                    "Error code: " + sqle.getErrorCode() + "\n\t\t" + 
                    "SQLState: " + sqle.getSQLState() + "\n";
                System.out.println(logMessage);
                sqle = sqle.getNextException();
            }
        } finally {
            try {
                if (connection != null)
                    connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
