Pacific-Design.com

    
Home Index

1. Java

2. MySQL Single

Java / MySQL Single /

Single Java Method to insert record

    
    public void insert_filenames(Collection<File> all) throws SQLException, ClassNotFoundException {

        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.1.100:3306/Database"
                                                    , "user", "password");

        String SQL = "INSERT INTO FILE_TABLE ( filename_id, processed ) VALUES ( ?, ? ); ";
        PreparedStatement stmt = conn.prepareStatement(SQL);

        for (File file : all) {
            System.out.println("File = " + file.toString());            
            stmt.setString(1, file.toString());
            stmt.setString(2, "new");
            stmt.executeUpdate();
        }
        
        stmt.close();
        conn.close();
    }