Download CS451 Introduction to Software Engineering

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CS451 Introduction to Software Engineering
Project 1: Skill Building (Group Project)
Build a small application with Web-interface (front-end) and database (back-end).



Step-0: Make a webpage for your group project and send the URL to the instructor
Step-1: Due date: Feb 1 (F), 2002
 Point: 3% of total grade
 Task:
 Be familiarized with JAVA compiler and editor (JCreater)
 Be familiarized with DBMS (MS Access)
 Create a simple database table using MS Access
 Access to database given by JDBC (refer to the sample example)
 Demonstrate database access/update for your example
 Submission: Post a documentation including Screen shots (application and
database table) to your group website
Step-2: Due date: Feb 8 (F), 2002
 Point: 3% of total grade
 Task
 Building a web interface for your application (built from step-1)
 You can select the technology for the web-interface implementation (HTML,
CGI, Java Applet, Servlet, JSP, etc)
 Demonstrate database access/update through the Web-interface
 Submission: Post a documentation including Screen shots (Web-interface,
application and database table) to your group website
Project 1-1 Example:
Database Connection using JDBC/ODBC
1. Create a simple Database using Microsoft Access. The DB contains only on table named
“account” which contains the balances for each customer in the below figure.
2. Setup System DSN under ODBC by adding Microsoft Access driver and named it “cs551” with
loginname “cs551” and password “password” as shown in the below figure.
The following is the JAVA source code for the Java Database Connectivity.
The program does the following methods
1.View Records
2.Update Records
3.Insert Records
4.Delete Records
---------------------------------------------------------------------------------------------------------//Importing the java packages
import java.io.*;
import java.sql.*;
import java.util.*;
//This is the main class
public class JDBCAccess
{
public static void main(String[] args){
try{
Connection con = getConnection();
con.setAutoCommit(false);
Statement stm = con.createStatement();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
int ch;
System.out.println("Enter 1 to retrieve the detials");
System.out.println(" 2 to update database");
System.out.println(" 3 to insert into database");
System.out.println(" 4 to delete from the database");
line = br.readLine();
ch=Integer.parseInt(line);
System.out.println(" The choice is"+ch);
switch(ch)
{
case 1:getTableInfo("userdb",stm);
stm.close();
break;
case 2:System.out.println("Iam here");
update1("userdb",stm);
con.commit();
stm.close();
break;
case 3:insert("userdb",stm);
con.commit();
stm.close();
break;
case 4:delete("userdb",stm);
con.commit();
stm.close();
break;
default:break;
}
}
catch(SQLException e){
System.out.println("SQLException:");
System.out.println("Message: " + e.getMessage());
}
catch(IOException e){
System.out.println("IOException:");
System.out.println("Message: " + e.getMessage());
}
catch(ClassNotFoundException e){
System.out.println("IOException:");
System.out.println("Message: " + e.getMessage());
}
}
//This method does the connection part with the database
public static Connection getConnection()throws SQLException, IOException, ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:userdb";
String username ="";
String password ="";
Enumeration e = DriverManager.getDrivers();
return DriverManager.getConnection(url,username,password);
}
//This method does the retrieving of the data
public static void getTableInfo(String table, Statement stm)throws SQLException,IOException
{
/*BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
int ch;
System.out.println("Enter the ID");
line = br.readLine();
ch=Integer.parseInt(line);*/
String qry = "Select * From "+ table;
ResultSet rs = stm.executeQuery(qry);
ResultSetMetaData rsmd = rs.getMetaData();
int count = rsmd.getColumnCount();
while (rs.next())
{
System.out.println();
for (int i=1;i<=count; i++)
{
System.out.println(rs.getString(i));
}
}
System.out.println();
rs.close();
}
//This method does the updating part
public static void update1(String userdb, Statement stmt)throws SQLException,IOException
{int ch;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line,temp1,temp2,temp3;
System.out.println("Enter the ID");
line = br.readLine();
ch=Integer.parseInt(line);
System.out.println("Please Enter the First Name");
temp1 = new String(br.readLine());
System.out.println("Please Enter the Last Name");
temp2 = new String(br.readLine( ));
System.out.println("Please Enter the Password");
temp2 = new String(br.readLine());
String sqlString = new String("UPDATE userdb SET
FirstName=temp1,LastName=temp2,Password=temp3 WHERE ID=ch ");
stmt.executeUpdate(sqlString); // Execute the update statement
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
//This method does the inserting part
public static void insert(String userdb, Statement stmt)throws SQLException,IOException
{
int ch;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line,temp1,temp2,temp3;
System.out.println("Please Enter the ID ");
line = br.readLine();
ch=Integer.parseInt(line);
System.out.println("Please Enter the First Name");
temp1 = new String(br.readLine());
System.out.println("Please Enter the Last Name");
temp2 = new String(br.readLine());
System.out.println("Please Enter the Password");
temp2 = new String(br.readLine());
String sqlString = new String("INSERT INTO userdb (ID,FirstName,LastName,Password) VALUES
(ch,temp1, temp2,temp3) ");
stmt.executeUpdate(sqlString); // Execute the insert statement
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
}
//This method does the deletion part
public static void delete(String userdb, Statement stmt)throws SQLException,IOException
{
int ch;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
System.out.println("Enter the ID");
line = br.readLine();
ch=Integer.parseInt(line);
String sqlString = new String("DELETE FROM userdb WHERE ID=ch");
stmt.executeUpdate(sqlString); // Execute the delete statement
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
This is the screen shot after the creation of userdb database.
After executing the program the screen shot is as follows. The user can choose one of the options.here
the user chooses to view details of userdb database record.
The user chooses to insert a new record into the database and gives the information about record.
The output screen shot of the userdb database.
The user chooses to update the database and gives the userid to identify record to be updated
screenshot after the updation.
The user chooses to delete a record from database and enters the userid. After the delete operation the
record with userid 5 is deleted from database.
screenshot of database after the deletion.
Related documents