I'm trying to get all the names of my movie files from a directory and i'm trying to store them in a database under the column movies.
One other column in the database labeled music already has some data, and the rows under the Movie column are null, so I'm trying to update these values using the update statement.
The program runs successfully but the data i'm trying to get is not stored in the database, the update statement i think is not working.
what do you think may be the problem? thanks
package organizer;
import java.io.File;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
/
public class Get_Files {
static Connection conn;
public static void main(String args[]) throws SQLException, ClassNotFoundException, InterruptedException, IOException,SQLSyntaxErrorException{
String driver = "org.apache.derby.jdbc.ClientDriver"; //driver url
String connectionURL = "jdbc:derby://localhost:1527/Organizer"; // connection url
String Username= "my_name"; //Username
String Password= "my_password"; //password
Class.forName(driver);//loads the driver
conn = DriverManager.getConnection(connectionURL,Username ,Password); //makes connection
String file_name;
File file = new File("G:\\Movies"); //PAth to files
File[] files = file.listFiles(); //Creates an array of files in the path.
ArrayList<String> Movies = new ArrayList<>();
for (int fileInList = 0; fileInList < files.length; fileInList++)
{
if (files[fileInList].isFile())
{
file_name = files[fileInList].getName().toString();
Movies.add(file_name); // adds file names into an array list
}
//System.out.println(files[fileInList].toString()+fileInList);
//Movies.add(files[fileInList].toString());
}
for(int x=0; x<files.length;x++)
{
// statement.executeUpdate("INSERT INTO APP.EXTERNAL_HD_FILES(ID,MUSIC)"//Executes Sql Statement
// + "values("+x+",'"+Movies.get(x)+"')");
//System.out.println(Movies.get(x));
try{
Statement statement = conn.createStatement();
String qry="UPDATE APP.EXTERNAL_HD_FILES" +
"SET MOVIES =\""+Movies.get(x)+"\" "
+" WHERE ID = '"+x+"'";
//System.out.println(qry);
statement.executeUpdate(qry);
}
catch(SQLException e){}
}
}
}