-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCode_lab3_01.java
More file actions
90 lines (90 loc) · 2.35 KB
/
Copy pathProjectCode_lab3_01.java
File metadata and controls
90 lines (90 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**********************************************
**
** Course: Database Systems
** Date: 03/18/2015
** Author: George Ray
** Description: Student starter code for JDBC
**
***********************************************/
import java.sql.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.util.List;
import java.io.IOException;
import java.nio.charset.Charset;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
public class cmsc461 {
public static void main(String[] args) {
/*********************************
*** Open Oracle JDBC driver
*** on error, exit
**********************************/
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException ex) {
ex.printStackTrace(System.err);
System.exit(1);
}
/*********************************
*** Call to internal method
*** getConnection for a
*** connection to the Oracle
*** database system
**********************************/
Connection con = getConnection(args);
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select table_name from user_tables");
while ( rs.next() ) {
String name = rs.getString(1);
System.out.println(name);
}
}
catch (SQLException se ){
System.out.println("Unable to list user tables");
se.printStackTrace();
System.exit(1);
}
try{
con.close();
}
catch (SQLException se ){
System.out.println("Unable to close connection");
se.printStackTrace();
System.exit(1);
}
/* end of method main, exit to system */
}
/***********************************
*** Method getConnection
***
***********************************/
public static Connection getConnection(String[] args) {
String userLogin = null, userPasswd = null;
if (args.length < 2) {
System.err.println("usage :: java cmsc461 <username> <passwd>");
System.exit(1);
}
else {
userLogin = args[0];
userPasswd = args[1];
}
String url = "jdbc:oracle:thin:@studentdb-oracle.gl.umbc.edu:1521/STUDENTDB";
Connection con = null;
try {
con = DriverManager.getConnection(url, userLogin, userPasswd);
System.out.println("Connected to Oracle.");
}
catch (SQLException se ){
System.out.println("Unable to connect to Oracle.");
se.printStackTrace();
System.exit(1);
}
return con;
}
/* end of class */
}