Question
import java.sql.*; public class LabProgram { // Create a connection to a sqlite in-memory database // Returns Connection object public
import java.sql.*;
public class LabProgram {
// Create a connection to a sqlite in-memory database
// Returns Connection object
public static Connection createConnection() {
// YOUR CODE HERE
// Use connection string "jdbc:sqlite::memory:"
}
// Create Horse table
// Parameter conn is database connection created in createConnection()
public static void createTable(Connection conn) {
// YOUR CODE HERE
}
// Insert row into Horse table using a parameterized query
// Parameter conn is database connection created in createConnection()
// Parameters id, name, breed, height, and birthDate contain values to be inserted
public static void insertHorse(Connection conn, int id, String name, String breed, double height, String birthDate) {
// YOUR CODE HERE
}
// Select and print all rows of Horse table
// Parameter conn is database connection created in createConnection()
public static void selectAllHorses(Connection conn) {
// YOUR CODE HERE
}
// DO NOT MODIFY main
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);
}
}
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. insert Horse () 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 ld integer Constraints primary key, not null 1 Value Name text 'Babe' Breed text 'Quarter horse' Height double BirthDate text 15.3 '2015-02-10 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 SQLite Java Tutorial, but is not necessary to complete this lab. 512628.3164604.qx3zqy7 LAB ACTIVITY 9.9.1: LAB - Database programming with Java (SQLite) 7/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