Find The Errors JAVA import java.sql.*; import java.util.HashMap; require java.u
ID: 3863205 • Letter: F
Question
Find The Errors
JAVA
import java.sql.*;
import java.util.HashMap;
require java.util.Map.Entry;
public class Main1{
public static void main{String[] args}
throws ClassNotFoundException, SQLException {
// Create Hashset that contains 4 Dog objects.
HashMap<string, Dog> col = new HashMap ();
col.put("D1", new Dog ("Duke","Maxwell", 3,"German shephard"));
col.put("D2", new Dog ("Sparky" "Rogers", 1, "Dachshund");
col.put("D3", new Dog ("Mimi" "Sanchez", 1, "Pomeranian"));
col.put("D4", new Dog ("Ginger" "Saari", 4, "Collie"));
system.out.printIn(col);
//Create Connection and statement objects.
Class.forName("org.sqlite.JDBC");
Connection c = DriverManager.
getConnction("jdbc:sqlite:dogs.db");
statement s = c.createStatement;
// Create new dogs table, if it doesn't already exist.
string sql1 = "create table if not exists dogs (" +
"name varchar(10)," +
"owner varchar(10), +
"age integer, " +
"breed varchar(10));";
s.executeUpdate(sql1);
//------Source code file Main1.java (continued)
//Populate table with dogs from collection.
for (Entry<String, Dog> e: col.entrySet()){
Dog d = e.getKey();
string sql2 = String.format{
"insert into dogs values ('%s', '%s',%d, %s);",
d.getName( ), getOwner( ), d.getAge( ),
d.getBreed);
s.executeUpdate (sql2);
}
}
Explanation / Answer
Hi
I have fixed the issues. Please find the updated code below.
Main1.java
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map.Entry;
public class Main1{
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// Create Hashset that contains 4 Dog objects.
HashMap<String, Dog> col = new HashMap <String, Dog>();
col.put("D1", new Dog ("Duke","Maxwell", 3,"German shephard"));
col.put("D2", new Dog ("Sparky" ,"Rogers", 1, "Dachshund"));
col.put("D3", new Dog ("Mimi" ,"Sanchez", 1, "Pomeranian"));
col.put("D4", new Dog ("Ginger" ,"Saari", 4, "Collie"));
System.out.println(col);
//Create Connection and statement objects.
Class.forName("org.sqlite.JDBC");
Connection c = DriverManager.getConnection("jdbc:sqlite:dogs.db");
Statement s = c.createStatement();
// Create new dogs table, if it doesn't already exist.
String sql1 = "create table if not exists dogs (" +
"name varchar(10)," +
"owner varchar(10)," +
"age integer, " +
"breed varchar(10));";
s.executeUpdate(sql1);
//------Source code file Main1.java (continued)
//Populate table with dogs from collection.
for (Entry<String, Dog> e: col.entrySet()){
Dog d = col.get(e.getKey());
String sql2 = String.format(
"insert into dogs values ('%s', '%s',%d, %s)",
d.getName( ), d.getOwner( ), d.getAge( ),
d.getBreed());
s.executeUpdate (sql2);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.