comparison m-toolbox/classes/+utils/@jmysql/jconnTodbconn.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % JCONNTODBCONN convert a java db connection to a MATLAB database
2 % connection.
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %
5 % DESCRIPTION: JCONNTODBCONN convert a java db connection to a MATLAB
6 % database Toolbox connection.
7 %
8 % CALL: dbconn = utils.jmysql.jconnTodbconn(jconn);
9 %
10 % INPUTS:
11 % jconn - a connection object like that returned from
12 % utils.jmysql.connect.
13 %
14 % OUTPUTS: dbconn - a database toolbox connecton
15 %
16 %
17 % VERSION: $Id: jconnTodbconn.m,v 1.1 2009/07/28 06:46:09 hewitson Exp $
18 %
19 % HISTORY: 24-05-2007 M Hewitson
20 % Creation
21 %
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
24
25
26 function conn = jconnTodbconn(jconn)
27
28 if nargin ~= 1 || ~isa(jconn, 'mpipeline.repository.RepositoryConnection')
29 error('### The first argument should be a RepositoryConnection');
30 end
31
32 host = char(jconn.getHostname);
33 db = char(jconn.getDatabase);
34 user = char(jconn.getUsername);
35 pw = char(jconn.getPassword);
36
37 dbdriver = getappdata(0, 'mysql_driver');
38 dburl = sprintf('jdbc:mysql://%s/%s',host,db);
39
40 disp(sprintf('** Connecting to %s as %s...', host, user))
41
42 conn = database(db,user,pw,dbdriver,dburl);
43 disp('** Connection status:')
44 disp(ping(conn))
45
46
47 end
48