-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadSQL.java
39 lines (37 loc) · 1.14 KB
/
ReadSQL.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
import java.sql.*;
import java.util.*;
import java.io.*;
/**
* read the SQL database.
* Username: Evan
* Password: apcs
* Off of standard driver.
* Reads off of the sales line ONLY.
*/
public class ReadSQL
{
public static boolean getConnection(String host,HashMap h) throws Exception {
try {
Class.forName("com.mysql.jdbc.Driver") ;
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", "Evan");
connectionProps.put("password", "apcs" );
conn = DriverManager.getConnection(host,connectionProps);
//System.out.println(conn);
int counter = 0;
Statement stmt = conn.createStatement() ;
String query = "select Sales from data ;";
ResultSet rs = stmt.executeQuery(query) ;
while (rs.next()) {
h.put(counter,rs.getString(1));
counter++;
}
}
catch (Exception e)
{
return false;
}
return true;
}
}