Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
943 views

NODE JS Lab Manual Part1

manual

Uploaded by

22wh1a1231
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
943 views

NODE JS Lab Manual Part1

manual

Uploaded by

22wh1a1231
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

1.

Build a web application with registration, login, catalog and cart pages using CSS3
features, flex and grid.
1. Project Setup:
⦁ Create three HTML files: index.html for the landing page,
⦁ register.html for registration, and
⦁ login.html for login.
⦁ Create a separate CSS file styles.css to style all pages.

Index.html

<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> SHOPPING WEBSITE </title>
<link rel="stylesheet" href="style.css">
</head>
<body align=”left">
<header>
<h1>HAPPY SHOPPING !!</h2>
</header>
<h1 align="left">Welcome to my Website..</h1>
<nav align="left">
<a href="registration.html">Registration form</a>
<a href="login.html">Login</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>

</body>
</html>

Registration.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav align="right">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="catalog.html">Registration Form</a>
<a href="cart.html">Cart</a>

</nav>

<h2>Registration Form</h2>
<form action="#" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>

<input type="submit" value="Submit">


</form>
</body>
</html>

Login.html

<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>

</nav>

</header>
<h1 align="left">LOGIN FORM</h1>
<form action="formex.html">
<table>
<tr>
<label> Name:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<tr>
<label>Password:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<label>Confirm Password:</label>
<tr>
<input type="text"><br>
</tr><br>
<button type="submit" class="btn btn-primary">Submit</button>
</table>
</form>
</body>
</html>

Catalog.html

<!DOCTYPE html>
<html lang="en">
<head>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>

</nav>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Catalog</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Product Catalog</h2>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product">
<h3>Hair Dryer</h3>
<p>Faszin Ionic Salon Hair Dryer, Professional Blow Dryer 2200W AC Motor Fast
Drying</p>
<p>Price: $19.99</p>
<button>Add to Cart</button>
</div>
</body>
</html>

Cart.html

<!DOCTYPE html>
<html lang="en">
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>

</nav>

</body>
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Shopping Cart</h2>

<div class="cart">
<h3>Cart Items</h3>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product" height="50" width="50">
<p>Hair Dryer</p>
<p>Price: $19.99</p>
<button>Remove</button>
</div>
<p>Total: $19.99</p>
<button>Checkout</button>
</div>
</body>
</html>

Styles.css

body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

header, main, footer {


padding: 20px;
}

header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f0f0f0;
}

nav {
display: flex;
gap: 10px;
}

main {
display: flex;
justify-content: center;
align-items: center;
min-height: calc(100vh - 160px); /* Account for header and footer heights */
}

.hero {
text-align: center;
}
OUTPUT
Index.html registration.html

Login.html
Catalog.html

Cart.html
2. Make the above web application a responsive web application using Bootstrap
framework.

1. Project Setup:

 Create three HTML files: index.html for the landing page,


 register.html for registration, and
 login.html for login.
 Create a separate CSS file styles.css to style all pages.

Index.html

<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> SHOPPING WEBSITE </title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="leftr">
<header>
<h1>HAPPY SHOPPING !!</h2>
</header>
<h1 align="left">Welcome to my Website..</h1>
<nav align="left">
<a href="registration.html">Registration form</a>
<a href="login.html">Login</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>

</body>
</html>

Registration.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="catalog.html">Registration Form</a>
<a href="cart.html">Cart</a>

</nav>

<h2>Registration Form</h2>
<form action="#" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>

<input type="submit" value="Submit">


</form>
</body>
</html>

Login.html

<html>
<head>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>

</nav>

</header>
<h1 align=”left">LOGIN FORM</h1>

<form action="formex.html">
<table >
<tr>
<label> Name:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<tr>
<label>Password:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<label>Confirm Password:</label>
<tr>
<input type="text"><br>
</tr><br>
<button type="submit" class="btn btn-primary">Submit</button>
</table>
</form>
</body>
</html>

Catalog.html
<!DOCTYPE html>
<html lang="en">
<head>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>

</nav>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Catalog</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Product Catalog</h2>

<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product">
<h3>Hair Dryer</h3>
<p>Faszin Ionic Salon Hair Dryer, Professional Blow Dryer 2200W AC Motor Fast
Drying</p>
<p>Price: $19.99</p>
<button>Add to Cart</button>
</div>
</body>
</html>

Cart.html

<!DOCTYPE html>
<html lang="en">
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>

</nav>

</body>
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Shopping Cart</h2>

<div class="cart">
<h3>Cart Items</h3>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product" height="50" width="50">
<p>Hair Dryer</p>
<p>Price: $19.99</p>
<button>Remove</button>
</div>
<p>Total: $19.99</p>
<button>Checkout</button>
</div>
</body>
</html>
Styles.css

body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

header, main, footer {


padding: 20px;
}

header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f0f0f0;
}

nav {
display: flex;
gap: 10px;
}

main {
display: flex;
justify-content: center;
align-items: center;
min-height: calc(100vh - 160px); /* Account for header and footer heights */
}

.hero {
text-align: center;
}
OUTPUT

Index.html registration.html

Login.html

Catalog.html
Cart.html
3. Use JavaScript for doing client – side validation of the pages implemented in
experiment 1 and experiment 2.
1. We include a separate script.js file to store our validation logic.
2. We use JavaScript to access form elements and set up an event listener for the
form's submit event.
3. Inside the event listener, we perform basic validations for username and password
fields:
a. Checking if the field is empty using isEmpty().
b. Checking if the password meets a minimum length requirement
using minLength().

4. We use alert() to display error messages to the user if validation fails.


5. We use event.preventDefault() to prevent the form from submitting if validation fails.

Index.html

<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> SHOPPING WEBSITE </title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<h1 >HAPPY SHOPPING !!</h2>
</header>
<h1 align="left">Welcome to my Website..</h1>
<nav align="left">
<a href="registration.html">Registration form</a>
<a href="login.html">Login</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>

</body>
</html>
Registration.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A NodeJs-ReactJs-Django\Lab
Programs\Program-2\bootstrap-5.0.2- dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2- dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="catalog.html">Registration Form</a>
<a href="cart.html">Cart</a>
</nav>

<h2>Registration Form</h2>
<form action="#" method="POST" onsubmit="return validateForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>

<input type="submit" value="Submit">


</form>

<script>
function validateForm() {
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;

// Simple validation for name and email fields


if (name.trim() == "") {
alert("Please enter your name.");
return false;
}

if (email.trim() == "") {
alert("Please enter your email.");
return false;
} else if (!validateEmail(email)) {
alert("Please enter a valid email address.");
return false;
}

return true;
}

function validateEmail(email) {
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
</script>
</body>
</html>

Login.html

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2- dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2- dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
</header>
<h1 align="left">LOGIN FORM</h1>
<form action="formex.html" onsubmit="return validateForm()">
<tr>
<td><label>Name:</label></td>
</tr>
<tr>
<td><input type="text" id="name"></td>
</tr>
<br>
<tr>
<td><label>Password:</label></td>
</tr>
<tr>
<td><input type="password" id="password"></td>
</tr>
<br>
<tr>
<td><label>Confirm Password:</label></td>
</tr>
<tr>
<td><input type="password" id="confirmPassword"></td>
</tr>
<br>
<tr>
<td><button type="submit" class="btn btn-primary">Submit</button></td>
</tr>
</table>
</form>
<script>
function validateForm() {
var name = document.getElementById("name").value;
var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirmPassword").value;

if (name.trim() == "") {
alert("Please enter your name.");
return false;
}

if (password.trim() == "") {
alert("Please enter your password.");
return false;
}

if (confirmPassword.trim() == "") {
alert("Please confirm your password.");
return false;
}

if (password !== confirmPassword) {


alert("Passwords do not match.");
return false;
}

return true;
}
</script>
</body>
</html>

Catalog.html

<!DOCTYPE html>
<html lang="en">
<head>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>

</nav>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Catalog</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Product Catalog</h2>

<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product">
<h3>Hair Dryer</h3>
<p>Faszin Ionic Salon Hair Dryer, Professional Blow Dryer 2200W AC Motor Fast
Drying</p>
<p>Price: $19.99</p>
<button>Add to Cart</button>
</div>
</body>
</html>

Cart.html

<!DOCTYPE html>
<html lang="en">
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>

</nav>

</body>
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Shopping Cart</h2>

<div class="cart">
<h3>Cart Items</h3>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product" height="50" width="50">
<p>Hair Dryer</p>
<p>Price: $19.99</p>
<button>Remove</button>
</div>
<p>Total: $19.99</p>
<button>Checkout</button>
</div>
</body>
</html>

Styles.css

body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

header, main, footer {


padding: 20px;
}

header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f0f0f0;
}

nav {
display: flex;
gap: 10px;
}

main {
display: flex;
justify-content: center;
align-items: center;
min-height: calc(100vh - 160px); /* Account for header and footer heights */
}

.hero {
text-align: center;
}

OUTPUT

Index.html
registration.html

Login.html
Catalog.html

Cart.html
4. Explore the features of ES6 like arrow functions, callbacks, promises, async/await.
Implement an application for reading the weather information from openweathermap.org
and display the information in the form of a graph on the web page.

CODE:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Weather Graph</title>

<style>

/* Change page background color to white */

body {

background-color: #fff;

color: #000; /* Set text color to black for better visibility */

text-align: center; /* Align text in the center */

font-family: 'Roboto', sans-serif;

/* Change border color */

#graph {

border: 5px solid #000; /* Change border color to jet black */


padding: 20px;

margin: 20px auto;

max-width: 800px;

display: inline-block; /* Keep the graph container centered */

/* Change chart line color */

#chart-container {

margin-top: 40px;

/* Change font */

#city {

font-size: 16px;

color: #000; /* Set input text color to black */

background-color: #fff; /* Set input background color to white */

border: 1px solid #000; /* Set input border color to black */

text-align: center; /* Align text in the center */

width: 200px; /* Set fixed width for input box */

box-sizing: border-box; /* Include padding and border in the input's total width */

margin-bottom: 10px; /* Add some space below the input */

/* Change font of the label */


label[for="city"] {

font-size: 18px;

color: #000; /* Set label text color to black */

display: block; /* Make label a block element */

margin-bottom: 10px; /* Add some space below the label */

/* Style the button */

#get-weather-button {

font-size: 16px;

color: #fff;

background-color: #333; /* Set button background color */

border: none;

padding: 10px 20px;

cursor: pointer;

#get-weather-button:hover {

background-color: #555; /* Darken button color on hover */

</style>

<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

</head>

<body>
<div id="graph">

<label for="city">Enter City:</label>

<br>

<input type="text" id="city" placeholder="Enter city name">

<br>

<button id="get-weather-button" onclick="fetchAndDisplay()">Get Weather</button>

<div id="chart-container">

<canvas id="myChart" width="800" height="400"></canvas>

</div>

</div>

<script>

async function fetchWeather(city) {

const apiKey = '17a7e1cc3e0a9e0f9304bd814e97e23a';

const apiUrl =
`https://api.openweathermap.org/data/2.5/forecast?q=${city}&appid=${apiKey}`;

try {

const response = await fetch(apiUrl);

const data = await response.json();

return data;

} catch (error) {

console.error('Error fetching weather data:', error);

return null;

}
}

function drawGraph(data) {

const chartContainer = document.getElementById('chart-container');

chartContainer.innerHTML = '';

const canvas = document.createElement('canvas');

canvas.setAttribute('id', 'myChart');

canvas.width = 800;

canvas.height = 400;

chartContainer.appendChild(canvas);

const ctx = canvas.getContext('2d');

const labels = data.map(entry => entry.time);

const temperatures = data.map(entry => entry.temperature);

new Chart(ctx), {

type: 'line',

data: {

labels: labels,

datasets: [{

label: 'Temperature (°C)',

backgroundColor: 'rgba(128, 0, 128, 0.2)', // Change temperature color to purple

borderColor: '#000', // Change graph line color to jet black for better visibility

data: temperatures,

borderWidth: 2 // Increase line width for better visibility

}]
},

options: {

responsive: false,

scales: {

y: {

beginAtZero: true,

grid: {

color: '#888' // Set grid color to light gray for better visibility

},

ticks: {

color: '#000' // Set tick color to black for better visibility

},

x: {

grid: {

color: '#888' // Set grid color to light gray for better visibility

},

ticks: {

color: '#000' // Set tick color to black for better visibility

}
});

async function fetchAndDisplay() {

const city = document.getElementById('city').value;

const weatherData = await fetchWeather(city);

if (weatherData && weatherData.list && weatherData.list.length > 0) {

const temperatures = weatherData.list.map(entry => ({

time: entry.dt_txt,

temperature: entry.main.temp - 273.15

}));

drawGraph(temperatures);

} else {

console.error('Failed to fetch weather data or no data found for the entered city.');

alert('Please enter a valid city name.');

</script>
5. Develop a java stand-alone application that connects with the database (Oracle
/ mySql) and perform the CRUD operation on the database tables

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class SQLDemoCommands {

public static void main(String[] args) {

Connection con = null;

Statement stmt = null;

try {

// Load the MySQL JDBC driver

Class.forName("com.mysql.cj.jdbc.Driver");

// Connect to the database

con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/sample?useSSL=false","root","1
2345");

// Create a SQL statement

Statement stmt =con.createStatement();


ResultSet rs = stmt.executeQuery("select *from student");

while(rs.next()){

int roll = rs.getInt("RollNo");

String name = rs.getString("Name");

String city = rs.getString("City");

System.out.println(roll+" "+name+" "+city);

// SQL query to insert values into the student table

String insertQuery = "INSERT INTO student VALUES (6, 'Akshara',


'BVRITH')";

// String insertQuery = "UPDATE student SET Name = 'BEEMLA' WHERE


RollNo=6";

//String s = "UPDATE student SET Name = 'BEEMLA' WHERE RollNo=6";

//String s = "DELETE FROM STUDENT WHERE RollNo=6";

//String s = "Select RollNo, Name, City from Student";

// Execute the INSERT statement

int rowsAffected = stmt.executeUpdate(insertQuery);

// Check if the insertion was successful

if (rowsAffected > 0) {

System.out.println("Data inserted successfully.");

} else {

System.out.println("Insertion failed.");
}

} catch (ClassNotFoundException | SQLException e) {

e.printStackTrace();

} finally {

// Close the resources in a finally block to ensure they're always closed

try {

if (stmt != null) {

stmt.close();

if (con != null) {

con.close();

} catch (SQLException e) {

e.printStackTrace();

}
6.Create an xml for the bookstore. Validate the same using both DTD and XSD.

FIRSTt.xml

<?xml version="1.0" encoding="UTF-8"?>

<bookstore name="My Awesome Books">

<book category="fiction">

<title>The Lord of the Rings</title>

<author>J.R.R. Tolkien</author>

<year>1954</year>

<price>25.00</price>

</book>

<book category="science fiction">

<title>Ender's Game</title>

<author>Orson Scott Card</author>

<year>1985</year>

<price>18.99</price>

</book>

</bookstore>

BOOKSTORE.dtd

<!ELEMENT bookstore (name, book+)>

<!ELEMENT name (#PCDATA)>

<!ELEMENT book (title, author, year, price) >

<!ELEMENT title (#PCDATA)>

<!ELEMENT author (#PCDATA)>


<!ELEMENT year (#PCDATA)>

<!ELEMENT price (#PCDATA)>

<!ATTLIST bookstore name CDATA #REQUIRED>

BOOKSTORE.XSD

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://mybookstore.com"

xmlns="http://mybookstore.com"

elementFormDefault="qualified">

<xs:element name="bookstore">

<xs:complexType>

<xs:attribute name="name" type="xs:string" use="required"/>

<xs:sequence>

<xs:element name="book" minOccurs="1" maxOccurs="unbounded">

<xs:complexType>

<xs:sequence>

<xs:element name="title" type="xs:string"/>

<xs:element name="author" type="xs:string"/>

<xs:element name="year" type="xs:integer"/>

<xs:element name="price" type="xs:decimal"/>

</xs:sequence>

</xs:complexType>
</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

You might also like