0

I have a table created in myFile.csv. I wanted to load this table into SQL database. I am working in C language under unix environment. I went through some links but I didn't get any useful direction. Thanks.

nobody
  • 19,814
  • 17
  • 56
  • 77
Sai
  • 31
  • 2
  • 5

3 Answers3

0

I think you are referring to a CSV file instead of a CVS file. CSV stands for Comma Seperated Values. To load data from C to a database you will need C libraries for the database that allow you to run SQL INSERT statements. C isn't suited really well for this task in this day and age. Java would likely be a better bet because because nearly all vendors provide JDBC drivers for this purpose. If you insist on doing this in C you will likely be using ODBC drivers or a native library for your database on non-Windows platforms. Some information about ODBC can be found at this link.

ojblass
  • 21,146
  • 22
  • 83
  • 132
0

This is not a direct answer to your question.

If you want to load a text file into an SQL database, you can do this usually with some helper program from the database in question. For MySQL, this could be LOAD DATA INFILE or mysqlimport

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

not a real code snippet, but just guidelines...

  1. read the file with fgets() , this will give you line by line output...
  2. for each line, tokenize it using strtok

    char *brkt; for (item = strtok_r(line, ",", &brkt); line; line = strtok_r(NULL, ",", &brkt)) {

    }

  3. connect to the database and send your query . i.e. mysqlconnect() for mysql

Leonardo Bernardini
  • 1,076
  • 13
  • 23