Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago