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.
3 Answers
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.

- 21,146
- 22
- 83
- 132
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

- 72,253
- 8
- 102
- 198
not a real code snippet, but just guidelines...
- read the file with fgets() , this will give you line by line output...
for each line, tokenize it using strtok
char *brkt; for (item = strtok_r(line, ",", &brkt); line; line = strtok_r(NULL, ",", &brkt)) {
}
connect to the database and send your query . i.e. mysqlconnect() for mysql

- 1,076
- 13
- 23