Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Can't get the Update statement to work

  1. #1
    Junior Member
    Join Date
    Mar 2012
    My Mood
    Thanked 0 Times in 0 Posts

    Unhappy Can't get the Update statement to work

    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



    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)+"')");

    Statement statement = conn.createStatement();

    "SET MOVIES =\""+Movies.get(x)+"\" "
    +" WHERE ID = '"+x+"'";

    catch(SQLException e){}



  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Thanked 206 Times in 182 Posts

    Default Re: Can't get the Update statement to work

    Also at java-forums.org

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    copeg (March 16th, 2012)

Similar Threads

  1. update database from List<>
    By beruska in forum JDBC & Databases
    Replies: 3
    Last Post: November 7th, 2011, 02:21 PM
  2. Update GUI before lengthy task
    By hafunui in forum Java Theory & Questions
    Replies: 2
    Last Post: October 17th, 2011, 11:24 AM
  3. Why my update.jsp is not working?
    By tangara in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: September 8th, 2011, 01:14 AM
  4. Update table in database
    By CTheSky in forum JDBC & Databases
    Replies: 4
    Last Post: February 24th, 2011, 01:02 AM

Tags for this Thread