Forum Stats

  • 3,733,360 Users
  • 2,246,748 Discussions
  • 7,856,667 Comments

Discussions

CHANGE THE OUTPUT TO INSERT DATA TO MYSQL'S TABLE

JOAO12
JOAO12 Member Posts: 1
edited August 2018 in MySQL Community Space

Hello,

Please, I need help to change the output of the following code,

I need the output to be to fill the column named `combinations`, that belongs to the table named `table1` of the MySQL's database named `numbers`.

At the moment, the results are displayed to the console, and I need to change it to fill a specified column of a table in MySQL.

Regards,

John

class Permutation {

    static void combinationUtil(int arr[], int data[], int start,

                                int end, int index, int r)

    {

        if (index == r)

        {

            for (int j=0; j<r; j++)

            System.out.print(data[j]+" ");

            System.out.println("");

            return;

        }

        for (int i=start; i<=end && end-i+1 >= r-index; i++)

        {

            data[index] = arr[i];

            combinationUtil(arr, data, i+1, end, index+1, r);

        }

    }

    static void printCombination(int arr[], int n, int r)

    {

        int data[]=new int[r];

        combinationUtil(arr, data, 0, n-1, 0, r);

    }

    public static void main (String[] args) {

        int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

        int r = 6;

        int n = arr.length;

        printCombination(arr, n, r);

    }

}

Answers

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,776 Bronze Crown
    edited August 2018

    There are a few ways that you could approach this.

    . Output the data to a file in CSV format and use mysqlimport to load said CSV file.

       mysqlimport

       LOAD DATA INFILE syntax

       ...and then make a system call ro mysqlimport to load the dat

    . Login to mysql via your program and create/run the insert statement/s directly, passing the values to the insert statement via bind variables/arrays.

    . Create a file of many insert statements and run that via a system call to mysql:

       system_call("mysql < file_with_mysql_commands.txt");

    Those are just a few options you could try.

Sign In or Register to comment.