Sample Output HTML file, after connecting to localhost C localhost:8080 PENELOPE GUINESS NICK WAHLBERG...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Sample Output HTML file, after connecting to localhost ← → C localhost:8080 PENELOPE GUINESS NICK WAHLBERG ED CHASE JENNIFER DAVIS JOHNNY LOLLOBRIGIDA BETTE NICHOLSON GRACE MOSTEL Overview In this assignment, you will use the MySQL module to connect to a MySQL Server. The application will run a simple select statement, iterate through the resultset, and display the records in the form of a simple HTML page using Node.js. Database https://dev.mysql.com/doc/sakila/en/ https://dev.mysql.com/doc/sakila/en/sakila-structure.html Work on the JavaScript file 4. Create Global Variables 4.1. Create a new JavaScript file named sql Test.js located in the project folder. 4.2. Import the http module using the require keyword at the top of the file. Assign the reference to a global variable named http. Use let to declare the variable. 4.3. Import the mysql module using the require keyword at the top of the file. Assign the reference to a global variable named mysql. Use let to declare the variable. 4.4. Declare a variable called output, which will store the HTML response output. 5. Call the initializeDB() method. You will write it shortly! 6. Create a Node.js Server 6.1. Invoke the createServer method using your http object. It requires a callback method as an argument. Use method name processServerRequest (you will create the method shortly). Store the reference in a new global variable named httpServer. 6.2. Start the server by invoking its listen method. Configure the server to listen on port 8080. Login: host: cis425.cviulu0113xf.us-west-2.rds.amazonaws.com database: sakila port: 3306 user: reader password: Go+Sun+Devils! 2. Install the mysql package using NPM 2.1. Open a command prompt or terminal window and change the directory to your project folder. 2.2. Use npm install mysql to install the mysql package within your project folder. 7. Implement the method to connect to the database and perform other database tasks Function Name: initializeDB Parameters: none Return value: none Purpose: This function will use the MySQL module to connect to the database, run a query and terminate the connection. 6.1 Declare a variable named connectionString and assign to a JavaScript object. It should have the following name/value pairs. Ensure that you are using the JSON namevalue structure (there is no array, so there will be no square brackets). Name host Value cis425.cviulu0113xf.us-west-2.rds.amazonaws.com port 3306 database sakila reader user password Go+Sun+Devils! 6.2 6.3 6.4 6.5 Log the connection string to the console. Create a connection by invoking the createConnection method of the mysql object. Pass the connectionString to the method as an argument. createConnection will return a reference to the new connection object. Store it in a new variable named con. Log that you are going to connect to the database. Start the connection by invoking the connect method of the con object. Pass an inline function declaration as an argument. The function should accept one variable, err, as an argument. The following statements are the body of the inline function. The function is anonymous, i.e. it doesn't have a name. 6.6 Use an if statement to test if there was an error (using the err variable). If so, log the error and throw the err object, i.e. "throw err;". Create a new SQL query and store it in a sql query variable. Select first_name, last name from the actor table. 6.7 Log that you are connected to the database. 6.8 6.9 Execute the query by invoking the query method of the con object. Pass the sql query text as an argument. In addition, the query method expects a callback function as an argument. Pass a reference to the method process Result as the second argument. (You will write the method shortly). 6.10 Terminate the connection by calling the end method of the con object. 9 Implement the method to process one record of the resultset. Function Name: printActor Parameters: one: record Return value: none Purpose: This method will process one record of the sql resultset. For each record, it will construct a paragraph element which contains the first and last names of the actor. The following parts are the body of the method. 9.1 Using string concatenation, append to the existing output variable. Append a new paragraph tag which contains the first_name and last_name attributes of the record. Use strong tags to make the last name bold. This all can be done in one line of code! 10 Test your Program 10.1 Open a command prompt or terminal window. 10.1.1 On MacOS, you can easily open a terminal window which is already within the folder. 10.1.2 On Windows, change directory to work in the exercise folder. You can use the cd command and paste the full folder path. 10.2 Type node followed by the name of the js file to run the file. 10.3 Open Chrome and navigate to the local host server using port 8080. If your program works, it should connect to the Node.js script and execute the full script. The Node.js program should then send an HTML response back. You should then see the first and last names of all actors within individual paragraph elements. Sample Output HTML file, after connecting to localhost ← → C localhost:8080 PENELOPE GUINESS NICK WAHLBERG ED CHASE JENNIFER DAVIS JOHNNY LOLLOBRIGIDA BETTE NICHOLSON GRACE MOSTEL Overview In this assignment, you will use the MySQL module to connect to a MySQL Server. The application will run a simple select statement, iterate through the resultset, and display the records in the form of a simple HTML page using Node.js. Database https://dev.mysql.com/doc/sakila/en/ https://dev.mysql.com/doc/sakila/en/sakila-structure.html Work on the JavaScript file 4. Create Global Variables 4.1. Create a new JavaScript file named sql Test.js located in the project folder. 4.2. Import the http module using the require keyword at the top of the file. Assign the reference to a global variable named http. Use let to declare the variable. 4.3. Import the mysql module using the require keyword at the top of the file. Assign the reference to a global variable named mysql. Use let to declare the variable. 4.4. Declare a variable called output, which will store the HTML response output. 5. Call the initializeDB() method. You will write it shortly! 6. Create a Node.js Server 6.1. Invoke the createServer method using your http object. It requires a callback method as an argument. Use method name processServerRequest (you will create the method shortly). Store the reference in a new global variable named httpServer. 6.2. Start the server by invoking its listen method. Configure the server to listen on port 8080. Login: host: cis425.cviulu0113xf.us-west-2.rds.amazonaws.com database: sakila port: 3306 user: reader password: Go+Sun+Devils! 2. Install the mysql package using NPM 2.1. Open a command prompt or terminal window and change the directory to your project folder. 2.2. Use npm install mysql to install the mysql package within your project folder. 7. Implement the method to connect to the database and perform other database tasks Function Name: initializeDB Parameters: none Return value: none Purpose: This function will use the MySQL module to connect to the database, run a query and terminate the connection. 6.1 Declare a variable named connectionString and assign to a JavaScript object. It should have the following name/value pairs. Ensure that you are using the JSON namevalue structure (there is no array, so there will be no square brackets). Name host Value cis425.cviulu0113xf.us-west-2.rds.amazonaws.com port 3306 database sakila reader user password Go+Sun+Devils! 6.2 6.3 6.4 6.5 Log the connection string to the console. Create a connection by invoking the createConnection method of the mysql object. Pass the connectionString to the method as an argument. createConnection will return a reference to the new connection object. Store it in a new variable named con. Log that you are going to connect to the database. Start the connection by invoking the connect method of the con object. Pass an inline function declaration as an argument. The function should accept one variable, err, as an argument. The following statements are the body of the inline function. The function is anonymous, i.e. it doesn't have a name. 6.6 Use an if statement to test if there was an error (using the err variable). If so, log the error and throw the err object, i.e. "throw err;". Create a new SQL query and store it in a sql query variable. Select first_name, last name from the actor table. 6.7 Log that you are connected to the database. 6.8 6.9 Execute the query by invoking the query method of the con object. Pass the sql query text as an argument. In addition, the query method expects a callback function as an argument. Pass a reference to the method process Result as the second argument. (You will write the method shortly). 6.10 Terminate the connection by calling the end method of the con object. 9 Implement the method to process one record of the resultset. Function Name: printActor Parameters: one: record Return value: none Purpose: This method will process one record of the sql resultset. For each record, it will construct a paragraph element which contains the first and last names of the actor. The following parts are the body of the method. 9.1 Using string concatenation, append to the existing output variable. Append a new paragraph tag which contains the first_name and last_name attributes of the record. Use strong tags to make the last name bold. This all can be done in one line of code! 10 Test your Program 10.1 Open a command prompt or terminal window. 10.1.1 On MacOS, you can easily open a terminal window which is already within the folder. 10.1.2 On Windows, change directory to work in the exercise folder. You can use the cd command and paste the full folder path. 10.2 Type node followed by the name of the js file to run the file. 10.3 Open Chrome and navigate to the local host server using port 8080. If your program works, it should connect to the Node.js script and execute the full script. The Node.js program should then send an HTML response back. You should then see the first and last names of all actors within individual paragraph elements.
Expert Answer:
Answer rating: 100% (QA)
Heres how you can solve the problem of connecting to a MySQL database from a Nodejs application and displaying actor information combining the insights from all five images 1 Install the MySQL Driver ... View the full answer
Related Book For
Introduction To Federal Income Taxation In Canada
ISBN: 9781554965021
33rd Edition
Authors: Robert E. Beam, Stanley N. Laiken, James J. Barnett
Posted Date:
Students also viewed these programming questions
-
Alex and Francesco are brothers who have different approaches to dealing with their investment portfolios. Alex is happy to invest passively; he will analyze the market once at the beginning, acquire...
-
Using quarterly data for 10 years, the regression results are given in the following table where CAR = number of new car sales per thousand population, PRICE = new car price index, INC= per-capita...
-
The following independent items for Theatre Dupuis during the year ended November 30, 2017, may require a transaction journal entry, an adjusting entry, or both. The company records all prepaid costs...
-
131I is given to a patient for use in a diagnostic procedure on her thyroid. What percentage of the 131I sample remains after exactly one day, assuming that all of the 131I is retained in the...
-
The dynamics of stock share prices over time may be difficult to model accurately, but interest rates are much more complex. In earlier chapters, we have considered continuously compounded interest...
-
Bicycling World, a magazine devoted to cycling, reviews hundreds of bicycles throughout the year. Its Road-Race category contains reviews of bicycles used by riders primarily interested in racing....
-
discuss the role of cognitive biases and heuristics in influencing persuasive communication strategies ?
-
Combustion of hydrocarbons such as pentane (C3H2) produces carbon dioxide, a "greenhouse gas." Greenhouse gases in the Earth's atmosphere can trap the Sun's heat, raising the average temperature of...
-
4. You are given a relational schema R = ABC, satisfying the following FDs 1. A B 2. AC 3. B C (a) Which normal forms are satisfied? (b) A decomposition into AB and AC is proposed. i. Which normal...
-
Discuss how personal insurance needs are similar or not similarto business needs. Choose and describe an insurance product that can be utilized in your personal life and how it can minimize your...
-
Imagine your client would like to complete a tax inversion, acquiring a foreign company in Switzerland and moving the domicile of the combined company overseas. Your client believes that this will...
-
discuss examples from your past, either at work, or university, where communication between levels caused problems. What was the cause of these issues? In what ways could this have been improved?...
-
A firm operates 2 0 0 days per year. The production rate of the firm is 2 0 0 couplings per day The steady coupling rate is 5 0 per day Additionally, it takes $ 4 for storing each coupling per year....
-
Q#5 Let A, B, C be nx n matrices. Verify that (a) A is similar to A. (b) If A is similar to B and B is similar to C, then A is similar to C.
-
4. Jobe dy -Y 2 et by
-
Ronal Canada Ltd. is a Canadian subsidiary of Ronal Inc., a U.S. multinational public corporation. You are the tax manager responsible for reviewing the corporate tax return and tax provision for the...
-
The unaudited income statement for Lomas & Sons Limited for its year ended December 31, 2012 shows the following: The information in the following notes has already been reflected in the above income...
-
Consider each of the following unrelated cases, involving the ownership of shares of Canadian-controlled private corporations. Assume all of the issued shares are common shares unless specifically...
-
The change in the annual spending rate, in conjunction with the boards expectations regarding future enrollment and the need for endowment support, could justify that KUEs target weight for: A....
-
Which of the characteristics put forth by Chaterji to describe the factor-based approach is/are correct? A. Only Characteristic 1 B. Only Characteristic 2 C. Both Characteristic 1 and Characteristic...
-
Based on Exhibits 1 and 2, to attempt to profit from the short-term excess return forecast, Capara should increase KUEs portfolio allocation to: A. developed markets equity and decrease its...
Study smarter with the SolutionInn App