Question
SQL USING CHINOOK DATABASE SCHEMA 1.1 IN JAVA CAN SOMEONE PLEASE HELP ME FIX THIS CODE. I AM HAVING TROUBLE GETTING THE PREPARED STATEMENT TO
SQL USING CHINOOK DATABASE SCHEMA 1.1 IN JAVA
CAN SOMEONE PLEASE HELP ME FIX THIS CODE. I AM HAVING TROUBLE GETTING THE PREPARED STATEMENT TO RETURN THE RESULTS.
import java.sql.Connection;
public class ChinookApp { /** * Exception handler for Usage statement */ private static class UsageException extends RuntimeException { UsageException() { usage(); } public void usage() { System.out.println("Usage: java ChinookApp
/** * Command-line Chinook utility * * @param args command-line arguments * @throws ClassNotFoundException cannot find JDBC driver * @throws SQLException SQL gone bad */ public static void main(String[] args) throws ClassNotFoundException { String sql= ""; // validates the inputs, exits if bad int queryNum = getQueryNumber(args); // load the sqlite-JDBC driver using the current class loader Class.forName( "org.sqlite.JDBC" ); String param=""; // makes a connection to the database try (Connection connection = DriverManager.getConnection("jdbc:sqlite:" + args[0])) { PreparedStatement stmt = connection.prepareStatement(sql); //stmt.setString(1, param); if (queryNum == 1) { sql = "SELECT *"+ "FROM Customer"+ "WHERE Customer.Country = ?";
} else if (queryNum == 2) { sql = "SELECT * Employee"+ "FROM Employee"+ "GROUP BY Employee.EmployeeId";
} else if (queryNum == 3) { sql = "SELECT EmployeeId"+ "count(CustomerId)"+ "FROM Employee"+ "customer"+ "WHERE SupportRepid=EmployeeId";
} else if (queryNum == 4) { sql = "SELECT * Customer"+ "FROM Customer"+ "GROUP BY Customer.CustomerId";
} else if (queryNum == 5) { sql = "SELECT InvoiceId"+ "CustomerId"+ "FROM invoices"+ "GROUP BY customerId"+ "ORDER BY InvoiceId";
} System.out.println(" SQL: " + sql + " "); // get results ResultSet res = stmt.executeQuery(sql); while ( res.next() ) { System.out.println("nSQL: " + res + " " ); } }catch (SQLException e) { System.out.println("Invalid database: " + e.getMessage()); throw new UsageException(); } } }
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