forked from abegaz/mentcareSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatientAdapter.java
63 lines (56 loc) · 1.78 KB
/
PatientAdapter.java
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
package com.mentCare.adapter;
import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PatientAdapter
{
private static Connection myConn;
private static final String USERNAME = "root";
//password is "dumb" for me. Probably different for you
private static final String PASSWORD = "dumb";
private static final String CONN_STRING = "jdbc:mysql://localhost/mentcareDB";
// connection method that connects us to the MySQL database
public static Connection getConnection() throws SQLException{
System.out.println("Connected to MentCare database successfully!");
return DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
}
// method that displays our errors in more detail if connection fails
public static void displayException(SQLException ex){
System.err.println("Error Message: " + ex.getMessage());
System.err.println("Error Code: " + ex.getErrorCode());
System.err.println("SQL Status: " + ex.getSQLState());
}
public static void connect()
{
try
{
// String host = "jdbc:mysql://localhost/mentcareDB";
// String userName = "root";
// String userPass = "dumb";
// if (myConn != null && !myConn.isClosed())
// myConn.close();
Connection myConn = getConnection();
}
catch(SQLException err)
{
System.out.println(err.getMessage( ));
}
}
public static ResultSet getResultSet(String tableName)
{
ResultSet MyResultSet=null;
try
{
Statement myStat = myConn.createStatement();
MyResultSet = myStat.executeQuery("SELECT * FROM "+tableName);
}
catch (SQLException err)
{
System.out.println( err.getMessage( ) );
}
return MyResultSet;
}
}