f



Oracle JDBC connect problems-ojdbc6.jar using Native Java commands OK from Matlab,but database toolbox not working -pls help with database toolbox configuration

Hi,

I am having some trouble using oracle and jdbc drivers. When I use the native java commands it works from Matlab and I can connect to a database, here is how I do this:

javaaddpath('T:\tmp\ojdbc6.jar')

aa = oracle.jdbc.pool.OracleDataSource()
aa.setDriverType('thin')
aa.setNetworkProtocol('tcp')
aa.setDatabaseName('TESTDB')
aa.setServerName('192.0.0.1')
aa.setPortNumber(1521)
aa.setUser('testuser')
aa.setPassword('testpassword')
aa.setServiceName('TESTING')

conn = aa.getConnection()
stmt = conn.createStatement();

query = 'select * from prices';
rs = stmt.executeQuery(query);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
However, when I try and use the Matlab database toolbox commands I get an error. I have copied the database toolbox commands below. 
Can you see what I am doing wrong, can someone please help me with the datbase() function? Thanks for your help

Tony

javaaddpath('T:\tmp\ojdbc6.jar')
conn = database('TESTDB', 'testuser', 'TESTING', 'Vendor', 'Oracle', 'DriverType', 'thin', 'Server', '192.0.0.1', 'PortNumber', 1521  )
conn =
       Instance: 'TESTDB'
       UserName: 'testuser'
         Driver: []
            URL: []
    Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
        Message: [1x142 char]
         Handle: 0
        TimeOut: 0
     AutoCommit: 'off'
           Type: 'Database Object'
query = 'select * from prices';
e = exec(conn, query);
e = 
    Message: 'Invalid connection.'          
0
Tony
12/26/2013 6:18:05 AM
comp.soft-sys.matlab 211264 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
2044 Views

Similar Articles

[PageSpeed] 33

"Tony " <matlabquestions21@gmail.com> wrote in message
[snip]
> javaaddpath('T:\tmp\ojdbc6.jar')
> conn = database('TESTDB', 'testuser', 'TESTING', 'Vendor', 'Oracle', 'DriverType', 'thin', 'Server', '192.0.0.1', 'PortNumber', 1521  )
> conn =
>        Instance: 'TESTDB'
>        UserName: 'testuser'
>          Driver: []
>             URL: []
>     Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
>         Message: [1x142 char]
>          Handle: 0
>         TimeOut: 0
>      AutoCommit: 'off'
>            Type: 'Database Object'
> query = 'select * from prices';
> e = exec(conn, query);
> e = 
>     Message: 'Invalid connection.'          

There is no point in running exec() if database() failed to establish a connection, as appears to be your case. Take a look at conn.Message to understand why.

Yair Altman 
http://UndocumentedMatlab.com 
Read my Matlab-Java book 
0
Yair
12/26/2013 8:31:15 AM
"Yair Altman" wrote in message <l9gpgj$han$1@newscl01ah.mathworks.com>...
> There is no point in running exec() if database() failed to establish a connection, as appears to be your case. Take a look at conn.Message to understand why.

Thanks for your reply.  Yes, I should have included that, here is the error message

>> conn
conn =
       Instance: 'TESTDB'
       UserName: 'testuser'
         Driver: []
            URL: []
    Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
        Message: 'Invalid Oracle URL specified: OracleDataSource.makeURL'
         Handle: 0
        TimeOut: 0
     AutoCommit: 'off'
           Type: 'Database Object'
>> 

Thanks for your help,

Tony
0
Tony
12/27/2013 12:35:13 AM
Reply: