I want to connect Matlab to Sql server.
this is my code:
db = database('ChifcoProd-2013-12-12-11-37', '', '', 'sqljdbc4.jar',...
'jdbc:microsoft:sqlserver://localhost:1433;database=ChifcoProd-2013-12-12-11-37')
error:
JDBC Driver Error: sqljdbc4.jar. Driver Not Found/Loaded
the driver is already installed and I added the path to javaclasspath but it doesn't work.
Try using the Help within MatLab, its very helpful.
You are using the correct database connection:
conn = database(instance,username,password,driver,databaseurl)
The example provided by MatLab looks like this:
Connect to an Oracle database via JDBC driver.
Connect to the database, test_db, using the user name, scott, and password, tiger. Use the JDBC driver, oracle.jdbc.driver.OracleDriver, to make the connection. The URL defined by the driver vendor is jdbc:oracle:oci7:
conn = database('test_db','scott','tiger',...
'oracle.jdbc.driver.OracleDriver','jdbc:oracle:oci7:')
OR
Microsoft SQL Server Authenticated Database Connection
Connect to a Microsoft SQL Server database with integrated Windows Authentication using a JDBC driver.
Close MATLAB if it is running.
Insert the path to the database driver JAR file in the classpath.txt file. The classpath.txt file is located at:
$MATLABROOT\toolbox\local\classpath.txt
The updated path entry should now include the full path to the driver. For example:
C:\DB_Drivers\sqljdbc_2.0\enu\sqljdbc4.jar
Insert the path to the folder containing sqljdbc_auth.dll in the librarypath.txt file. The librarypath.txt file is located at:
$MATLABROOT\toolbox\local\librarypath.txt
The path entry should not include the file name sqljdbc_auth.dll:
C:\DB_Drivers\sqljdbc_2.0\enu\auth\x64
The sqljdbc_auth.dll file is installed in the following location:
<installation>\sqljdbc_<version>\<language>\auth\<arch>
where is the installation directory of the SQL server driver.
If you are running a 32-bit Java Virtual Machine (JVM), then use the
sqljdbc_auth.dll file in the x86 folder, even if the operating system
is the x64 version.
If you are running a 64-bit JVM on a x64 processor, then use the
sqljdbc_auth.dll file in the x64 folder.
If you are running a 64-bit JVM on a IA-64 processor, then use the
sqljdbc_auth.dll file in the IA64 folder.
Start MATLAB.
Use the AuthType parameter to establish a Windows Authentication connection.
conn = database('dbName','','', ...
'Vendor','Microsoft SQL Server','Server','servername',...
'AuthType','Windows')
Related
We have a need to connect to a PG database using Microsoft Access 2018.
I downloaded the ODBC driver ( psqlodbc_12_01_0000-x64.zip). I made sure the driver was also added to the system path in environment variables ( C:\Program Files\psqlODBC\1201\bin) for both the user and the system. I then restarted my computer.
I checked the OBDC Drive in Admin and the drivers are listed.
I do have a 64-bit OS
When I try to make a connection to it in Microsoft Access ( External Data > New Data Source > Select Data Source > Machine Data Source > New) it doesn't appear as an option to connect to. What am I missing here?
I downloaded and installed on Windows the following:
IBM DB2 Runtime Client (64-Bit) 10.5
with the aim of connecting to a remote server database.
It installed here:
C:\Program Files\IBM\SQLLIB
But I don't see any DB2 folders in there.
I tried to catalog the remote db like this:
db2 catalog tcpip node testing remote the.server.com server 446
If I then try to connect to it, I get the following:
SQL1031N The database directory cannot be found on the indicated file system.
There is some wizard installed called the 'Default DB2 and IBM Database Client Interface Selection Wizard'. I ran this and it said it would create a default DB2 copy and would be used by default, called DB2COPY1 and it would be installed to C:\Program Files\IBM\SQLLIB.
But I'm nnot sure what this is doing really.
What do I need to do here to connect to the remote DB2??
EDIT:
I have managed to get a bit further based on this article here:
https://www-01.ibm.com/support/docview.wss?uid=swg21008914
my current commands look like:
db2 catalog tcpip node tstnode remote my.server.com server 446
db2 catalog db db1name as mytstdb at node tstnode authentication server
db2 catalog dcs db db1name as A123456DAT
db2 terminate
db2 connect to mytstdb user <username> using <password>
However the connect fails with:
SQL30061N The database alias or database name "A123456DAT " was not
found at the remote node. SQLSTATE=08004
Any ideas?
If you are connecting through port 446, I guess you are trying to connect to DB2 for IBM z or DB2 for IBM i. If yes, you will need at least Db2 Connect.
Regarding error "SQL30061N The database alias or database name "A123456DAT " was not found at the remote node. SQLSTATE=08004" it happens to me when the userid does not have some priviledges on the source system. If it is an IBM i, look at the corresponding spool file. DRDA Connections are attended by jobs called QRWTSRVR. With the IBM i command WRKSPLF SELECT(USERID) (changing USERID by the user trying the DRDA connection) you can see the spool files for jobs related to your connection. Usually spool file messages are very specific on the cause of the failure.
If you are trying to connect to DB2 on z, I don't have experience.
I'm currently upgrading a project from Java 7 to Java 8, thus I switched from using the JDBC-ODBC Bridge to using UCanAccess. The database I want to connect to is registered as a system DSN so I connected to it like this:
Database.forURL("jdbc:odbc:MyDB" + ";DB_CLOSE_DELAY=-1;charSet=Cp1250", driver = "sun.jdbc.odbc.JdbcOdbcDriver")
Now I changed that to
Database.forURL("jdbc:ucanaccess:MyDB" + ";DB_CLOSE_DELAY=-1;charSet=Cp1250", driver = "net.ucanaccess.jdbc.UcanaccessDriver")
but that gives me the error:
Driver net.ucanaccess.jdbc.UcanaccessDriver does not know how to handle URL jdbc:ucanaccess:MyDB;DB_CLOSE_DELAY=-1;charSet=Cp1250
Is there a way to access a DSN via UCanAccess?
Is there a way to access a DSN via UCanAccess?
Not directly. UCanAccess is a JDBC driver that does not use ODBC, so it has no knowledge of ODBC DSNs.
Your UCanAccess connection string needs to include the path to the Access database file, e.g.,
jdbc:ucanaccess://C:/path/to/mydata.accdb
If necessary, you could retrieve that file path from the configuration information for an ODBC DSN. On Windows, the information for a System DSN named MyDB would be in the Windows registry under
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyDb
or perhaps
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\MyDb
When try to connect to DB2 Z/OS, the following error message is displayed,
[jcc][t4][10509][13454][3.67.28] Connection to the data server failed. The IBM Data Server for JDBC and SQLJ license was invalid or was not activated for the DB2 for z/OS subsystem. If you are connecting directly to the data server and using DB2 Connect Unlimited Edition for System z, perform the activation step by running the activation program in the license activation kit. If you are using any other edition of DB2 Connect, obtain the license file, db2jcc_license_cisuz.jar, from the license activation kit, and follow the installation directions to include the license file in the class path. ERRORCODE=-4230, SQLSTATE=42968"
For a ADS DB2 Z/OS connection,you do need the DB2 z/OS JDBC driver license file. You can fix the problem below with these steps ...
Close ADStudio
Download this driver file
Unzip the contents into the /lib/drivers> folder
Start ADStudio and then connect to DB2 z/OS.
I am using squirrel to connect to DB2 database.
I am able to successfully connect to one of our DB2 databases. But when I create a new connection to point to another db2 database, I get the below mentioned error.
java.util.concurrent.ExecutionException: java.lang.RuntimeException: com.ibm.db2.jcc.am.SqlSyntaxErrorException: [jcc]...... Connection to the data server failed. The IBM Data Server for JDBC and SQLJ license was invalid
or was not activated for the DB2 for z/OS subsystem. If you are connecting directly to
the data server and using DB2 Connect Unlimited Edition for System z, perform the
activation step by running the activation program in the license activation kit.
If you are using any other edition of DB2 Connect, obtain the license file,
db2jcc_license_cisuz.jar, from the license activation kit, and follow the installation
directions to include the license file in the class path. ERRORCODE=-4230, SQLSTATE=42968
I also tried to create a new Driver to use in Squirrel, But that too doesnot work.
I have db2jcc_license_cisuz.jar available in the same folder where I pointed my driver jar.
I am really surprised why one connection to DB2 works and the other doesn't work.
db2jcc_license_cisuz.jar must be in CLASSPATH. Check db2jcc_license_cisuz.jar in Java Class Path or Extra Class Path in driver properties.