Nothing Special   »   [go: up one dir, main page]

JDBC Program List: 1. Using JDBC, Create Table Called CONTACT - INFO With The Following Fields

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

JDBC Program List

1. Using JDBC, create table called CONTACT_INFO with the following fields:

CONTACT_ID FIRST_NAME MI LAST_NAME STREET CITY STATE ZIP

INTEGER VARCHAR(20) CHAR(1) VARCHAR(30) VARCHAR(50) VARCHAR(30) VARCHAR(30) VARCHAR(30)

NOT NULL NOT NULL, NULL, NOT NULL, NOT NULL, NOT NULL, NOT NULL, NOT NULL.

PRIMARY KEY,

2. Using JDBC, ALTER the above table as add one field call PHONE with data type varchar(16) and EMAIL varchar(50). 3. Using JDBC, insert data into above table. 4. Using JDBC, update city and state value by using condition and display number of rows updated.

(Create a Property file called database.properties. Store your driver name, url, dbName, username, password in that property file. By using Properties class and its method load drivers and establish connection. Use this method for establishing connection to the database for following programs.)
5. Using executeQuery method of statement class selects the data from above table into result set and display first name, last name, phone and Email as a formatted output.
6. Using result set get the metadata of a result set such as column count, column name of a

particular column by passing its index, column type of a column by passing its index, column label of a column by passing its index. 7. Create a table student, with following column: Int studentid; String name; String course; String grade;

Insert the data using prepared statement; select all the data in resultset. By using resultset objects methods, print all the data. Then drop the table student and commit transaction and close resultset, statement and connection object. 8. Create a table employee, with following column: Int empid; String firstname; String lastname; Int age; Then perform the following sequence.
a. Create SQL statements with placeholders. b. Create PrepareStatement object using prepareStatement()methods. c. Set auto-commit to false using setAutoCommit(). d. Add as many as SQL statements you like into batch using addBatch()method on

created statement object.


e. Execute all the SQL statements using executeBatch() method on created statement

object.
f. Finally, commit all the changes using commit() method, if all transactions in batch are

successfully executed, else rollback the transactions. 9. Create a table Product with following column: ProductId ProductName ProductPrice Discount Int String Int Int

Create the Scrollable and Updatable ResultSet and reduce the price of 3rd record by 50 Rs. Reduce the price of last record by Discount percentage. Increase the price of 2nd and 4th record by 20 Rs.
10.

Create two tables called employee and orders as follows:

CREATE TABLE Employees (Employee_ID INTEGER,Name VARCHAR(30));CREATE TABLE Orders (Prod_ID INTEGER,ProductName VARCHAR(20),Employee_ID INTEGER);Create a menu with following option, perform an action according to users choice.

Content of menu are : 1.Create Employees Table 2.Create Orders Table 3.Insert data into Employees Table 4.Insert data into Orders Table 5.Retrieve data for Employees Table 6.Retrieve data for Orders Table 7.Update Employees Table 8.Update Employees Table Using a Prepared Statement 9.Update many records of Orders Table Using a Prepared Statement 10.List the name of employees who bought CD 0.Exit

You might also like