1
$\begingroup$

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.

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

1 Answer 1

2
$\begingroup$

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;
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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