-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSVReader.java
More file actions
46 lines (40 loc) · 1.54 KB
/
CSVReader.java
File metadata and controls
46 lines (40 loc) · 1.54 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
package kitordersystem;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
* This is called when the database is reset, from the main menu, its only
* function is to repopulate the items database, which it does from a CSV
* file so that the contents of the table can be edited if the items ever
* change without having to recompile the whole program.
*/
public class CSVReader {
/**
* @throws IOException
* @throws SQLException
* @throws SAXException
* @throws ParserConfigurationException
*/
public CSVReader() throws IOException, SQLException, SAXException,
ParserConfigurationException {
BufferedReader reader = new BufferedReader(new FileReader("/Users/" +
"tsmoffat/kitordersystem/kitordersystem/kitordersystem/Hope" +
".csv"));
Connection c = new getConnection().getConnection();
Statement st = c.createStatement();
st.executeUpdate("use mydb");
String line = "";
while ((line = reader.readLine()) != null) {
String[] item = line.trim().split(",");
// if you want to check either it contains some name
// index 0 is first name, index 1 is last name, index 2 is ID
st.executeUpdate("insert into Items (Item) values (\"" + item[1]
+ "\")");
}
}
}