Question: I should create a connection between the database and java program I did create the final private constants private static final String URL = jdbc:.....;
I should create a connection between the database and java program I did create the final private constants
private static final String URL = "jdbc:.....";
private static final String USERNAME = "jj@table220"; private static final String PASSWORD = "table220";
than I have to create a public method called enterPlayers(), It must accept an argument called players of type Collection. It must not return a value. Declare an instance of Connection called connection with its value set to null. and I create the database connection and statement, my question is how I should loop through the players using for loop or iteration where I create inside the for loop Query variable to delete from the table players where the number of the player for example 10, and create a new statement so I can execute the query and then change the value of the Query variable to insert into players values (number, name, position, 'year'). and then execute the statement where this method insert a new row in the table but my code should not anticipate a return value from executeQuery(), so as soon as the method is invoked, we go to the next loop iteration
printing to the console, Inserting player into database: #2 jj (f, senior);
this is my cod
//Create method insertPlayers public Collection void insertPlayers(players) {
Collection players = new ArrayList(); //declare connection variable Connection conn = null; try { conn = DriverManager.getConnection(URL, USERNAME, PASSWORD); //loop through the players for (int i=1; i<=10; i++) { //create String String query = "delete from Players where number = 15"; //create statement by passing query to conn.createstatement Statement stmt = conn.createStatement(); //execute the update ResultSet rs = stmt.executeUpdate(query); //Change the value of query to contain an SQL Insert query string query = "insert into players values (20, 'John jones', 'B', 'Senior')"; //execute the query ResultSet rs1 = stmt.executeUpdate(query); }