65 591
Assignments Done
99,2%
Successfully Done
In October 2018

Answer to Question #24270 in Java | JSP | JSF for patrick

Question #24270
you have a single aircraft with 40 which flies between New York and London. the first 10 seats a first class while the rest are economy. passengers are required to make bookings for their flights. seats can be reserved and unavailable when paid for. implement the plane as a linked list of seats nodes, in java. seats can be added or removed from the plane as desired. this plane can then be checked if it is empty or full when making a reservation for a customer or if there is a desired seat available. implement an appropriate interface the user or clerk will be using to make these reservations. a reservation should have the traveler's details and the seats reserved and this information needs to be stored persistently. you are required to use a database. i just need the help with communicating with the database. just the explanation please .<br><br>
Expert's answer
First of all you will need a database connector. You canget it from your database&#039;s official website. Let&#039;s for example use MySQL
database.

You can get the connector here: http://dev.mysql.com/usingmysql/java/
You next step will be creating SQL tables for yourentities (bookings), where all the data is represented by plain text (Strings,
numeric types, Date type e.t.c.) The method you execute transactions to
database vary from language to language. Here&#039;s a java example:
import java.sql.*;
class Example{
private Connection connection;
public voidinit() {
Properties p =new Properties();
//user and password are set in your db configuration
p.setProperty(&quot;user&quot;, &quot;root&quot;);
p.setProperty(&quot;password&quot;, &quot;pwd&quot;);
try {
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
} catch (ClassNotFoundException e) {
// TODOAuto-generated catch block
e.printStackTrace();
}
StringconnectionURL = &quot;jdbc:mysql://localhost/yourDatabaseName&quot;;
try {
connection= DriverManager.getConnection(connectionURL, p);
} catch(SQLException e) {
// TODOAuto-generated catch block
e.printStackTrace();
}
}
}

And that&#039;s it. You can use &#039;connection&#039; object anywhereExecuting SQL statements:

PreparedStatement ps = null;
String sql = &quot;SELECT * FROM userdata WHEREusername=?&quot;;
ps =connection.prepareStatement(sql);
ps.executeQuery();

That&#039;s all the basics

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions