Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

# Java #JDBC Hi! I am trying to finish my java hw about jdbc, but I always fail on join the two table together and

# Java #JDBC

Hi! I am trying to finish my java hw about jdbc, but I always fail on join the two table together and write a code to let the user input the data in console to insert new row in my database.

Please help me to:

1. Create revenue report that generated from the cruise passengers by nationality and age

2. Create a report about sailors' data, the cruise they work on and their supervisors

3. make the user easily to input the passengers and cruise in the console, so the data will directly be added into the database.

*****Since I create many classes, so I put my code, SQLite database and jar in here: https://drive.google.com/drive/folders/1-zoEep1ILdnxKZszPc_QC05orbQy4rb-?usp=sharing*****

And here is what I try to write an insert method to insert the row in Cruise table, but it fails :( So I didn't put in my code in that link

private Connection connect() throws ClassNotFoundException { // SQLite connection string String url = ("org.sqlite.JDBC"); Connection conn = null; try { conn = DriverManager.getConnection("jdbc:sqlite:Database_Cruise.sqlite"); } catch (SQLException e) { System.out.println(e.getMessage()); } return conn; } /**  * Insert a new row into the warehouses table  */  public void insertRow(String sailing_date, String return_date, String departure_port, String ship_name, String cruise_serial_number) { String sql = "INSERT INTO Cruise(sailing_date,return_date,departure_port,ship_name,cruise_serial_number) VALUES(?,?,?,?,?)"; try (Connection conn = this.connect(); PreparedStatement pstmt = conn.prepareStatement(sql)) { pstmt.setString(1, sailing_date); pstmt.setString(2, return_date); pstmt.setString(3, departure_port); pstmt.setString(4, ship_name); pstmt.setString(5,cruise_serial_number); pstmt.executeUpdate(); } catch (SQLException e) { System.out.println(e.getMessage()); } catch (ClassNotFoundException e) { e.printStackTrace(); } }

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_2

Step: 3

blur-text-image_3

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students explore these related Databases questions