Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am working with database using OpenSQLConnection-JDBC. I am able to fetch the data perfectly from the tables but I cannot get nor the names of the tables (using SQLTableNames) neither the column names (using SQLColumnNames). I tried also to work with the help examples; but I got same problem.

what could be the reason?

conn = OpenSQLConnection[ 
  JDBC["MySQL(Connector/J)", 
   "IP/databasename"], 
  "Username" -> "username", "Password" -> "password"]

eventsdata = SQLSelect[
  conn, "tablename",
  SQLColumn["columnname"] == somevalue]

where: IP= Ip address of the database, databasename=database name that I am connecting to, tablename=table name which I have it before, columnname=columns names of the table that I have it before, somevalue=value so that I can fetch some of the data.

share|improve this question
    
What command are you using to fetch the data? Can you show us the code that works? –  mfvonh Jun 25 at 4:22
    
@mfvonh I have add part of the code that works. –  Algohi Jun 25 at 4:50
    
What output do you get when you try these: SQLTables[conn], SQLTableNames[conn], SQLTableInformation[conn]? –  mfvonh Jun 25 at 4:52
    
I got all empty list {}. –  Algohi Jun 25 at 4:53
    
Try SQLExecute[conn, "use tablename"] and then SQLTables[conn]. (with a real table name of course) –  mfvonh Jun 25 at 4:58

1 Answer 1

I would suggest to use SQL directly. For Oracle databases the following module should work.

Module[{dbConn, sqlAct, records},
"SELECT TABLE_NAME,COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME like'%your table name%'"// Set[sqlAct, #] &;
OpenSQLConnection["your connection"] // Set[dbConn, #] &;
SQLExecute[dbConn, sqlAct] // Set[records, #] &;
CloseSQLConnection[dbConn];
records
] // MatrixForm // Print;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.