For the code snippet listed below, fill in the code snippet based on the followi
ID: 3798625 • Letter: F
Question
For the code snippet listed below, fill in the code snippet based on the following information.
We have a SalesRep table that has the following fields, where we assume that there is a SalesRep with a SaleRepNumber value of 15.
SalesRepNumber Integer
SalesRepName VARCHAR
Also, use the following string information.
String dataBaseURL = "jdbc:mysql://localhost:3306/Sales";
String userName = "Tom";
String passWord ="giraffe";
You will need to build a SELECT STATEMENT that searches for the SalesRepName based on the SalesRepNumber field having a value of 15.
try
{
String dataBaseURL = "";
String userName = "";
String passWord ="";
Connection connection = DriverManager.getConnection(dataBaseURL,userName,passWord);
Statement statement= connnection.createStatement();
ResultSet rs = statement.executeQuery("");
System.out.println(rs.getString(""));
}
catch (SQLException e)
{
e.printStackTrace();
}
Explanation / Answer
Hi,
I have updated the code and highlighted the code changes below.
import java.sql.*;
public class SalesRepTest {
public static void main(String[] args) {
try
{
String dataBaseURL =
"jdbc:mysql://localhost:3306/Sales";
String userName = "Tom";
String passWord ="giraffe";
Connection connection
=DriverManager.getConnection(dataBaseURL,userName,passWord);
Statement statement=
connection.createStatement();
ResultSet rs = statement.executeQuery("select SalesRepNumber from SalesRep where SalesRepNumber = 15");
System.out.println(rs.getString(""));
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}