Question: public static Connection createConnection ( ) throws SQLException { String url = jdbc:sqlite::in - memory; Connection connection = DriverManager.getConnection ( url ) ; return
public static Connection createConnection throws SQLException
String url jdbc:sqlite::inmemory";
Connection connection DriverManager.getConnectionurl;
return connection;
createTable: This method is used to create the Horse table. The table should have five columns: Id Name, Breed, Height, and BirthDate. The Id column is an integer with primary key and not null constraints. The other columns are of type text and have specific values. You can use the following code:
java
public static void createTableConnection connection throws SQLException
String query "CREATE TABLE Horse Id INTEGER PRIMARY KEY NOT NULL, Name TEXT, Breed TEXT, Height DOUBLE, BirthDate TEXT;
Statement statement connection.createStatement;
statement.executequery;
insertHorse: This method is used to insert one row into the Horse table. You need to insert the specific values mentioned in the question. You can use the following code:
java
public static void insertHorseConnection connection throws SQLException
String query "INSERT INTO Horse Id Name, Breed, Height, BirthDate VALUES 'Babe', 'Quarter Horse', ;
Statement statement connection.createStatement;
statement.executequery;
selectAllHorses: This method is used to output all the rows from the Horse table. You can use the following code:
java
public static void selectAllHorsesConnection connection throws SQLException
String query "SELECT FROM Horse";
Statement statement connection.createStatement;
ResultSet resultSet statement.executeQueryquery;
while resultSetnext
int id resultSet.getIntId;
String name resultSet.getStringName;
String breed resultSet.getStringBreed;
double height resultSet.getDoubleHeight;
String birthDate resultSet.getStringBirthDate;
System.out.println id name breed height birthDate ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
