0% found this document useful (0 votes)
42 views4 pages

University of Melbourne (Semester-2 2011) Department of Computer Science and Software Engineering

This document contains the lab report for Lab 4 of the Engineering for Internet Applications course completed by Tooba Aamir. The report includes: 1. Instructions to manually display the contents of the database table and include output for test cases of inserting, listing, and deleting a URL from the table. 2. The full Java source code used to connect to a MySQL database called URLCollection, execute SQL statements to list, insert, and delete URLs, and print the results. 3. Information about the course, student, and date submitted at the top.

Uploaded by

Tooba Aamir
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

University of Melbourne (Semester-2 2011) Department of Computer Science and Software Engineering

This document contains the lab report for Lab 4 of the Engineering for Internet Applications course completed by Tooba Aamir. The report includes: 1. Instructions to manually display the contents of the database table and include output for test cases of inserting, listing, and deleting a URL from the table. 2. The full Java source code used to connect to a MySQL database called URLCollection, execute SQL statements to list, insert, and delete URLs, and print the results. 3. Information about the course, student, and date submitted at the top.

Uploaded by

Tooba Aamir
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Engineering for Internet Applications Lab 4 Tooba Aamir - 396447

University of Melbourne (Semester-2 2011) Department of Computer Science and Software Engineering

Course title Engineering for Internet Applications

Submitted by: Tooba Aamir 396447

Dated September, 2 2011

Engineering for Internet Applications Lab 4 Tooba Aamir - 396447 1. Manually display the contents of your database/table

Engineering for Internet Applications Lab 4 Tooba Aamir - 396447 2. Copy-and-paste the output of your program for some test cases.
Test cases include first 'insert' of URL ID 5 then 'list' of all table and at end delete' of URL ID 5.

3. Include your entire source code in your report.


import import import import java.sql.*; java.io.BufferedReader; java.io.IOException; java.io.InputStreamReader;

public class Connect { public static void main(String[] args) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName = "URLCollection"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = "ciit"; String c = "1"; try { Class.forName(driver); conn = DriverManager.getConnection(url+dbName,userName,password);

Engineering for Internet Applications Lab 4 Tooba Aamir - 396447


System.out.println("Connected to the database"); //------Statement s = conn.createStatement (); while(!(c.equals("0"))) { System.out.println ("Enter '1' to list all URLs\t'2' to delete URl\t'3' to insert URL\t'0' to to quit"); String st = br.readLine(); c = st; if (st.equals("1")) { s.executeQuery ("SELECT ID, url, EnterAt FROM urls"); ResultSet rs = s.getResultSet (); while (rs.next ()) { String IDVal = rs.getString ("ID"); String nameVal = rs.getString ("url"); String catVal = rs.getString ("EnterAt"); System.out.println (IDVal + ": URL = " + nameVal + ", Entry Date = " + catVal); } rs.close (); } else if (st.equals("2")) { System.out.println ("Enter URL ID to delete"); String st2 = br.readLine(); int delete = s.executeUpdate("DELETE FROM urls WHERE ID='"+st2+"'"); } else if (st.equals("3")) { System.out.println ("Enter URL ID"); String st2 = br.readLine(); System.out.println ("Enter URL"); String st3 = br.readLine(); System.out.println ("Enter date (yy/mm/dd)"); String st4 = br.readLine(); int insert = s.executeUpdate("INSERT INTO urls VALUES ('"+st2+"','"+st3+"','"+st4+"')"); } } s.close (); //------conn.close(); System.out.println("Disconnected from database"); } catch (Exception e) { e.printStackTrace(); } } }

You might also like