Question: 9 . 9 LAB - Database programming with Java LAB 9 . 9 . 1 : LAB - Database programming with Java Complete the Java

9.9 LAB - Database programming with Java
LAB
9.9.1: LAB - Database programming with Java
Complete the Java program to create a Horse table, insert one row, and print the row.
Implement the following methods. Method parameters are described in the template. Do not modify the main program. createConnection() creates a connection to the database. This method calls DriverManager.getConnection() with the following connection information:
- User: root
- Server address: 127.0.0.1
- Database: zybooksdb
Password is not necessary and can be omitted.
createTable () creates Horse, with five columns:
- ID - integer, primary key, not null
- Name - varchar(30)
- Breed - varchar(30)
- Height-double
- Birthdate - varchar(10)
Before creating Horse, drop the table if the table exists (from a prior run).
insertHorse () inserts one row into Horse:
(1, 'Babe', 'Quarter horse', 15.3,'2015-02-10')
selectAllHorses () selects and prints all Horse rows, as follows:
All horses:
(1, 'Babe', 'Quarter Horse', 15.3,'2015-02-10')
HINT: Use import java.sql.* to access all classes and methods of the Java-SQL API. Calls to these methods may throw exceptions and must be enclosed in the try block of a try-catch statement.
LabProgram.java
```
import java.sql.*;
public class LabProgram {
// Create a database connection
public static Connection createConnection(){
// Create a connection to 'zybooksdb' database
// :return: Connection object
// YOUR CODE HERE
}
// Create Horse table
public static void createTable(Connection conn){
// Create Horse table
// :param conn: Connection object
// :return: Nothing
```
Coding trail of your work What is this?
11/9 S-.--0-..-. U--. min:16
Latest submission -12:40 PM EST on 11/09/24
Only show failing tests
Open submission's code
1: Unit test all methods
\(0/9\)
Only show failing tests
Open submission's code
1: Unit test all methods
Test createConnection(, createTable(), and insertHorse) methods
file named HorseDatabase.java
public class HorseDatabase \{
/usercode/zyLabsUnitTest.java:16: error: cannot access LabProgram conn = LabProgram.createConnection();
bad source file: /usercode/LabProgram.java
file does not contain class LabProgram
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
2 errors
2: Compare output
Compare output
```
/usercode/LabProgram.java:7: error: class HorseDatabase is public, should be declared in a
file named HorseDatabase.java
public class HorseDatabase {
1 error
```
9 . 9 LAB - Database programming with Java LAB 9

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!