so basically i'm making my program via a console-based menu, yeah? it's a database manager and it's operated by answering with numbers(y'know, enter '1' to enter a record, enter '2' to export records, etc..). so there's no different ways to mess with the parameters, here. but it doesn't seem to be working anyway? here's my code, afterwards i'll tell you what i tried.
public void loadCSV(String table, String filename) {
String query;
try (Statement st = con.createStatement()) {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DrSoheirManager", "root", "ITGS!!!");
st = con.createStatement();
query = "load data local infile '/Users/****/NetBeansProjects/IA Draft 3/" +
filename + "' ignore into table " + table + " columns terminated
by ',' \n" + " lines terminated by '\\n'";
/* load data local infile '/users/****/netbeansprojects/ia draft
3/patients.csv' ignore into table */
st.execute(query);
} catch (Exception e) {
e.printStackTrace();
st = null;
}
}
so how the method (should) be used, is basically: loadCSV("patients", patients.csv); where patients is the name of the table where i want to enter the values, and patients.csv is the source of the values i want to enter. this is my first time working with the JDBC so i'm unfamiliar with the methods involved, but i've tried replacing st.execute(query) with st.executeQuery() and st.executeUpdate(), neither worked. beforehand i was getting an error but changing the SQL query a bit seemed to have fixed that. now i'm not getting an error, but the information just isn't being added to the database.
ps: i used the 'ignore' function because i want to be able to import to the database without adding duplicates. have i done this correctly?
if i am violating any rules by posting this please let me know so i can fix my errors. thank you in advance :)
edit: my schema:
and a sample data set:
CREATE TABLE IF NOT EXISTS `Patients` (
`ID` int(11) NOT NULL,
`fname` text NOT NULL,
`lname` text NOT NULL,
`Diagnosis` text NOT NULL,
`phone` varchar(15) NOT NULL,
`email` varchar(25) NOT NULL,
`DOB` date NOT NULL,
`DOFV` date NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
INSERT INTO `Patients` (`ID`, `fname`, `lname`, `Diagnosis`, `phone`, `email`, `DOB`, `DOFV`) VALUES
(1, 'hanalei', 'ezz', 'hemophelia', '+1(919)929-6567', 'hana@hanalei.me', '1998-08-22', '2008-03-12'),
(2, 'monika', 'zanesco', 'sickle cell disease', '+1(919)939-4264', 'monika.z@gmail.com', '1998-10-05', '2016-04-13'),
(3, 'bang', 'pham', 'leukemia', '+1(919)243-8937', 'bangp@aol.com', '1998-03-15', '2013-03-03');