Sunday, August 30, 2020

ODBC with J to connect to MySQL Database

If you are using the J programming language and wish to connect to a DBMS (MySQL, PostgreSQL, etc), you can use J's ODBC interface. We really only need to use the dd package for this. Let's assume we have a MySQL server running on localhost and listenign to port 3306 (default port for MySQL). Our database is testDB, our user and password are user1 and pass1 respectively.


load 'dd'

[ch=. ddcon 'server=0.0.0.0:3306;uid=user1;pwd=pass1;database=testDB;driver=mysql'
 



Here, ch is our connection handle, which we need to perform all subsequent database operations. We can make a query. Let's get the first 10 records of the "User" table.


sh=. 'SELECT * FROM Users' ddsel ch
ddfet sh,10



UPDATEing, CREATEing, DELETEing functionality is equally easy. For example we can update a User record:


query=. 'UPDATE Users SET Status = 1 WHERE Id = 1234;'''
   query ddsql ch
0





see also:

ODBC with J to connect to MySQL Database

If you are using the J programming language and wish to connect to a DBMS (MySQL, PostgreSQL, etc), you can use J's ODBC interface. W...