Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Suppose you have a Java DB database on your system named inventoryDB. What da

ID: 3530363 • Letter: 1

Question

1. Suppose you have a Java DB database on your system named inventoryDB. What database UKI would you use in a Java program to get a connection to the database? 2. What static JDBC method do you call to get a connection to a database? 3. Assume that a database has a table named Inventory, with the following columns: Column Name Type ProductID CHAR(IO) QtyOnHand INT Cost DOUBLE a) Write a SELECT statement that will return all of the column* friHii every row in table. b) Write a SELECT statement that will return the ProductiD column from ever)' row in table. C) Write a SELECT statement that will return the ProductiD column an J the QtyOnHand column from even* row in table. d) Write a SELECT statement that will return the ProductiD column only from the rows where Cott is less than 17.00. e) Write a SELECT statement that will return all of the columns from the rows where ProductiD ends with " / . / " . 4. Assume that the following declarations exist: final String DB_URL = "jdbc:derby:CoffeeDB"; String sql = "SELECT + FROM Coffee"; Write code that uses these String objects to get a database connection and execute the SQL statement. Be sure to close the connection when done. 5. Where does a ReaultSet objects cursor initially point? How do you move the cursor forward in the result set? 6. Assume that a valid ResultSet object exists, populated with data. What method do you call to retrieve column 3 as a string? What do you past at an argument to the method?

Explanation / Answer

I have answered all your question.Please rate this 5 and feel free to ask an doubts.Thanks


---------------------------------------------------

Ans 2)DriverManager.getConnection() is the static method used to get connections

----------------------------------

Ans 3)

a) select ProductId fromInventory ;

b)select ProductId from Inventory where row_id%2=0;

c) select ProductId,QtyOnHand from Inventory where row_id%2=0;

d)select ProductId from Inventory where cott<17.0;

e) select ProductId from Inventory where ProductId like "%/./"

---------------------------------------------------------------------------------------

Ans 4) String host="jdbc:derby//localhost:1527/CofeeDb"

String uName="asdf";

String pwd="qwerty";

Connection con=DriverManager.getConnection(host,uName,pwd);

Statement st=con.createStatement();

String sql="SELECT * FROM COFEE";

ResultSet rs=st.executeQuery(sql);

while(rs.next())

{

//your code to retrieve column in variables

}

---------------------------------------------

Ans 5.

---------------------------------------------------

A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.


ResultSet Types


The type of a ResultSet object determines the level of its functionality in two areas: the ways in which the cursor can be manipulated, and how concurrent changes made to the underlying data source are reflected by the ResultSet object.


The sensitivity of a ResultSet object is determined by one of three different ResultSet types:


TYPE_FORWARD_ONLY: The result set cannot be scrolled; its cursor moves forward only, from before the first row to after the last row.


TYPE_SCROLL_INSENSITIVE: The result can be scrolled; its cursor can move both forward and backward relative to the current position, and it can move to an absolute position


TYPE_SCROLL_SENSITIVE: The result can be scrolled; its cursor can move both forward and backward relative to the current position, and it can move to an absolute position.


Statement stmt = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");


now u can use

while(rs.next())

{

//your code

}

----------------------------------------------------------------------------------------------------------------------------------------------

Ans 6)

--------------------------------------------------------------------