|
Revision 109, 2.7 kB
(checked in by rajlich, 3 years ago)
|
*** empty log message ***
|
- Property svn:eol-style set to
native
- Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
import java.util.Vector; |
|---|
| 7 |
import java.io.*; |
|---|
| 8 |
import java.sql.*; |
|---|
| 9 |
import java.util.*; |
|---|
| 10 |
import java.text.*; |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
public class ConDB { |
|---|
| 18 |
|
|---|
| 19 |
Connection connection; |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
public ConDB(){ |
|---|
| 28 |
System.out.println("Trying to connect to the Monitors database"); |
|---|
| 29 |
login("monitors", "2172442757"); |
|---|
| 30 |
System.out.println("Connected to the Monitors database"); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
public ConDB (String username, String password) { |
|---|
| 40 |
System.out.println("Trying to connect to the db"); |
|---|
| 41 |
login(username, password); |
|---|
| 42 |
System.out.println("Connected to the database"); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
void login(String username, String password) { |
|---|
| 54 |
final String DRIVER = "org.gjt.mm.mysql.Driver"; |
|---|
| 55 |
final String URL ="jdbc:mysql://www3.isrl.uiuc.edu/monitors?user="+username+"&password="+password; |
|---|
| 56 |
|
|---|
| 57 |
try{ |
|---|
| 58 |
Class c= Class.forName(DRIVER); |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
connection = DriverManager.getConnection(URL); |
|---|
| 62 |
} |
|---|
| 63 |
catch(ClassNotFoundException e) { |
|---|
| 64 |
System.err.println("Cannot load Driver"); |
|---|
| 65 |
System.exit(1); |
|---|
| 66 |
} |
|---|
| 67 |
catch(SQLException e) { |
|---|
| 68 |
e.printStackTrace(); |
|---|
| 69 |
System.err.println("Cant Connect"); |
|---|
| 70 |
System.exit(1); |
|---|
| 71 |
} |
|---|
| 72 |
catch (Exception e) { |
|---|
| 73 |
System.err.println(e.getMessage()); |
|---|
| 74 |
System.exit(0); |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
public Connection getConnection() { |
|---|
| 87 |
return connection; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
public void close() { |
|---|
| 98 |
try { |
|---|
| 99 |
connection.close(); |
|---|
| 100 |
} |
|---|
| 101 |
catch (Exception e) { |
|---|
| 102 |
e.printStackTrace(); |
|---|
| 103 |
} |
|---|
| 104 |
System.out.println("Closed DB connection"); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
} |
|---|
| 109 |
|
|---|