-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLVisitLoader.java
97 lines (82 loc) · 2.82 KB
/
SQLVisitLoader.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
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
91
92
93
94
95
96
97
import java.sql.*;
public class SQLVisitLoader {
public static String USERNAME = new String("USER"); //replace user with local username
public static String PASSWORD = new String("PASSWORD"); //replace password with local user's password
public static String DB_URL = new String("jdbc:mysql://localhost:3306/DB_NAME_REPLACE"); //replace DB_NAME_REPLACE to the database you are using.
public static String JDBC_DRIVER = new String("com.mysql.jdbc.Driver"); //this is the SQL driver. don't need to replace.
public ResultSet getVisit() throws ClassNotFoundException {
Class.forName(JDBC_DRIVER);
try
{
// Get a connection from the connection factory
Connection con = DriverManager.getConnection(
DB_URL,
//"jdbc:oracle:thin:@dbaprod1:1521:SHR1_PRD",
USERNAME, PASSWORD);
// Create a Statement object so we can submit SQL statements to the driver
Statement stmt = con.createStatement();
// Submit a query, creating a ResultSet object
ResultSet rs = stmt.executeQuery("SELECT * FROM VISIT");
return rs;
}
catch (SQLException e)
{
System.out.println(e);
return null;
}
}
public int getVisitID() throws ClassNotFoundException {
Class.forName(JDBC_DRIVER);
try
{
// Get a connection from the connection factory
Connection con = DriverManager.getConnection(
DB_URL,
//"jdbc:oracle:thin:@dbaprod1:1521:SHR1_PRD",
USERNAME, PASSWORD);
// Create a Statement object so we can submit SQL statements to the driver
Statement stmt = con.createStatement();
// Submit a query, creating a ResultSet object
ResultSet rs = stmt.executeQuery("SELECT * FROM VISIT");
rs.last();
int last = rs.getInt(1);
System.out.println(last);
rs.close();
stmt.close();
con.close();
return (last + 1);
}
catch (SQLException e)
{
System.out.println(e);
return -1;
}
}
public int getVisitSeq(String THC) throws ClassNotFoundException {
Class.forName(JDBC_DRIVER);
try
{
// Get a connection from the connection factory
Connection con = DriverManager.getConnection(
DB_URL,
//"jdbc:oracle:thin:@dbaprod1:1521:SHR1_PRD",
USERNAME, PASSWORD);
// Create a Statement object so we can submit SQL statements to the driver
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
// Submit a query, creating a ResultSet object
ResultSet rs = stmt.executeQuery("SELECT * FROM VISIT WHERE THC =" + THC);
rs.last();
int last = rs.getRow();
rs.close();
stmt.close();
con.close();
return (last + 1);
}
catch (SQLException e)
{
System.out.println(e);
return -1;
}
}
}