Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please, I need some help with this one. I have been trying to upload the question for two days now and the website will not
Please, I need some help with this one. I have been trying to upload the question for two days now and the website will not let me upload the ScreenShots plus the code I have. I have been back & forth with Tech Support and they have no answers for me as to why. I hope this gets me in touch with someone so I can send them all the necessary code and screenshots of the question. The two suggested answers for this have errors and are not correct.
My library > DAT/390: Database Integration with Other Systems home > 5.9: LAB - Database programming with Java (SQLite) zyBooks catalog 5.9 LAB - Database programming with Java (SQLite) Complete the Java program to create a Horse table, insert one row, and display the row. The main program calls four methods: 1. createConnection ( ) creates a connection to the database. 2. createTable( ) creates the Horse table. 3. insertHorse () inserts one row into Horse. 4. selectAllHorses ( ) outputs all Horse rows. Complete all four methods. Method parameters are described in the template. Do not modify the main program. The Horse table should have five columns, with the following names, data types, constraints, and values: Name Data type Constraints Value Id integer primary key, not null 1 Name text 'Babe' Breed text 'Quarter horse' Height double 15.3 BirthDate text '2015-02-10' The program output should be:The program output should be: All horses: (1, 'Babe', 'Quarter Horse', 15.3, '2015-02-10') This lab uses the SQLite database rather than MySQL. Both SQLite and MySQL Connector/J implement the JDBC API. Consequently, the API is as described in the text, with a few exceptions: . Use the connection string "jdbc:sqlite::in-memory" to connect to an in-memory database. . Use the text data type instead of char and varchar. SQLite reference information can be found at SOLite Java Tutorial, but is not necessary to complete this lab. 500194.1690278.qx3zqy7 LAB 5.9.1: LAB - Database programming with Java (SQLite) 4 / 10 ACTIVITY LabProgram.java Load default template...Latest submission - 11:23 AM EDT on 08/01/23 Total score: 4 / 10 Only show failing tests Download this submission 1:Unit test A 1 /1 Test createConnection() returns valid connection Your test produced no output. 2:Unit test A 0/3 Test create Table() creates Horse table Test feedback Horse table does not exist 3:Unit test A 3/3 Test insertHorse() inserts row into Horse table Your test produced no output.Test insertHorse() inserts row into Horse table Your test produced no output. 4:Compare output A 0/3 Output is nearly correct, but whitespace differs. See highlights below. Special character legend All horses: Your output (1, 'Babe', 'Quarter Horse', 15.3, '2015-02-10') - All horses : Expected output (1, 'Babe' , 'Quarter Horse', 15.3, '2015-02-10')Latest submission - 11:23 AM EDT on 08/01/23 Total score: 4 / 10 Only show failing tests Download this submission 1:Unit test A 1 /1 Test createConnection() returns valid connection Your test produced no output. 2:Unit test A 0/3 Test create Table() creates Horse table Test feedback Horse table does not exist 3:Unit test A 3/3 Test insertHorse() inserts row into Horse table Your test produced no output.Test insertHorse() inserts row into Horse table Your test produced no output. 4:Compare output A 0/3 Output is nearly correct, but whitespace differs. See highlights below. Special character legend All horses: Your output (1, 'Babe', 'Quarter Horse', 15.3, '2015-02-10') - All horses : Expected output (1, 'Babe' , 'Quarter Horse', 15.3, '2015-02-10')Latest submission - 4:10 PM EDT on 08/02/23 Total score: 0 / 10 Download this submission Failed to compile LabProgram. java: 3: error: class HorseProgram is public, should be declared in a file named H public class HorseProgram { 1 errorimport java. sql.*; public class LabProgram { private static final String CREATE_HORSE_TABLE_SQL = "CREATE TABLE HORSE " + "(ID INT PRIMARY KEY NOT NULL, NAME TEXT, BREED TEXT, HEIGHT REAL, BIRTHDATE TEXT)"; private static final String INSERT_HORSE_SQL "INSERT INTO HORSE(ID, NAME, BREED, HEIGHT, BIRTHDATE) VALUES (?, ?, ?, ?, ?)"; private static final String SELECT_HORSE_SQL = "SELECT * FROM HORSE"; public static Connection createConnection( ) { Connection conn = null; try { Class. forName ("org. sqlite. JDBC") ; conn = DriverManager . getConnection("jdbc: sqlite: :memory:"); } catch (SQLException e) { System. err. printIn(e. getMessage( ) ) ; } catch (ClassNotFoundException e) { System. err . printIn(e. getMessage( ) ); return conn; public static void createTable(Connection conn) { Statement stmt = null; try { stmt = conn. createStatement( ) ; stmt . execute (CREATE_HORSE_TABLE_SQL) ; } catch (SQLException e) { System. err . printIn(e. getMessage ( ) ) ; } finally { if (stmt != null) { try {stmt . close () ; } catch (SQLException e) { public static void insertHorse (Connection conn, int id, String name, String breed, double height, String birthDate) { PreparedStatement pst = null; try { pst = conn. prepareStatement(INSERT_HORSE_SQL) ; pst. setInt(1, id); pst. setString(2, name); pst. setString(3, breed); pst. setDouble(4, height); pst. setString(5, birthDate); pst. execute ( ) ; } catch (SQLException e) { System. err . printIn(e. getMessage( ) ) ; } finally { if(pst != null) { try { pst . close( ); } catch (SQLException e) { System. err . printIn(e. getMessage( ) ); public static void selectAllHorses(Connection conn) { PreparedStatement pst = null;ResultSet rs = null; try { pst = conn . prepareStatement (SELECT_HORSE_SQL) ; rs = pst. executeQuery ( ) ; System. out. printIn("All horses:"); if (rs != null) { while(rs. next() ) { int id = rs. getInt("ID"); String name = rs. getString("NAME") ; String breed = rs. getString("BREED") ; double height = rs. getDouble("HEIGHT"); String dob = rs. getString("BIRTHDATE"); System. out. printIn("(" + id +", "" + name + "'. ""+breed + "" " + height +", "" + dob + "")") ; }// while } else { System. out. printIn("No horse found in database."); } } catch (SQLException e) { System. err . printIn(e. getMessage( ) ) ; } finally { if (rs != null) { try { rs. close() ; } catch (SQLException e) { System. err . printIn(e. getMessage( ) ) ; if (pst != null) { try { pst . close(); } catch (SQLException e) { System. err . printIn(e. getMessage ( ) ) ;public static void main(String args) { // Create connection to sqlite in-memory database Connection conn = createConnection( ); / / Create Horse table createTable(conn) ; // Insert row into Horse table insertHorse(conn, 1, "Babe", "Quarter Horse", 15.3, "2015-02-10"); // select and print all Horse table rows selectAllHorses (conn) ;4:Compare output 0/3 Output is nearly correct, but whitespace differs. See highlights below. Special character legend All horses: Your output (1, 'Babe', 'Quarter Horse', 15.3, '2015-02-10') - All horses: Expected output (1, 'Babe', 'Quarter Horse', 15.3, '2015-02-10')Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started