Re: Unable to import/output files with MySQL
Thanks for the reply.
I'm pretty shit at this so i'll try to convey this as best i can:
Here is my code in java:
Main:
public class MainFile {
public static void main(String[] args) {
DBConnection database = new DBConnection ("Inventory.txt", "Output.log");
Connection c = database.connect("jdbc:mysql://localhost:3306/inventorydb","root","root");
database.DBImport(c);
}
}
DBConnection:
import java.sql.*;
import java.util.logging.*;
public class DBConnection {
private Statement s;
private Connection c;
private ResultSet rs;
private String inf;
private String outf;
public DBConnection(String InputFile, String OutputFile){
setInputFile(InputFile);
setOutputFile(OutputFile);
}
public void setInputFile(String InputFile){
inf = InputFile;
}
public void setOutputFile(String OutputFile){
outf = OutputFile;
}
public Connection connect(String port, String user, String password){
try {
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection(port, user, password);
}
catch (Exception e){
System.out.println("Error: "+ e);
}
return c;
}
public void DBImport(Connection c){
String insert = "LOAD DATA INFILE '" +inf+ "' INTO TABLE Inventory (name, price, stock);";
String query = "SELECT * FROM Inventory";
String createTable = "CREATE TABLE Inventory "
+ "(id INT NOT NULL AUTO INCREMENT PRIMARY KEY,"
+ "name varchar(45) NOT NULL,"
+ "price integer not null,"
+ "stock integer not null);";
String modify = "ALTER TABLE Inventory ";//inc
Logger log = Logger.getLogger(outf);//Setting up the log file
FileHandler fh;
try{
fh = new FileHandler("C:/ProgramData/MySQL/MySQL Server 5.5/data/Output.log");//I cant get it to read/write these files!
log.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
}
catch(Exception e){
System.out.println(e);
}
try{
s = c.createStatement();
//s.execute(createTable);//Create the table
//log.info("Table created");//log it
s.executeUpdate(insert);//Load it with info
log.info("Table populated");//log it
rs = s.executeQuery(query);//Check on it
log.info("Table Queried");//log it
//s.executeUpdate(modify);//Modify the table
//log.info("Modification made: "+modify);//log it
}
catch(Exception e){
System.out.println("Error: "+ e);
}
}
}
Its incomplete and im sure theres errors all around, i dont want to concern you with bug fixing this, just the secure file priv problem.
So in regards to your reply:
1. I haven't been able to find a command line client to MySQL server 5.7, if you have the link please post it.
2. I believe i have both options of doing this on the command line client or in java, but i went the route of setting up the database and the client and using java to connect to the database and populate it with data
3. Im pretty sure that it is connected to the 5.5 server because 5.5 is currently taking port 3306, which is the port my code is accessing.
The 5.7 client is uninstalled, however there are still lingering files on my pc so you may be right in this.