diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@jmysql/jconnTodbconn.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,48 @@
+% JCONNTODBCONN convert a java db connection to a MATLAB database
+% connection.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: JCONNTODBCONN convert a java db connection to a MATLAB
+%              database Toolbox connection.
+%
+% CALL:        dbconn = utils.jmysql.jconnTodbconn(jconn);
+%
+% INPUTS:
+%              jconn - a connection object like that returned from
+%                     utils.jmysql.connect.
+% 
+% OUTPUTS:     dbconn - a database toolbox connecton
+%
+%
+% VERSION:     $Id: jconnTodbconn.m,v 1.1 2009/07/28 06:46:09 hewitson Exp $
+%
+% HISTORY:     24-05-2007 M Hewitson
+%                 Creation
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+function conn = jconnTodbconn(jconn)
+  
+  if nargin ~= 1 || ~isa(jconn, 'mpipeline.repository.RepositoryConnection')
+    error('### The first argument should be a RepositoryConnection');
+  end
+
+  host = char(jconn.getHostname);
+  db   = char(jconn.getDatabase);
+  user = char(jconn.getUsername);
+  pw   = char(jconn.getPassword);
+  
+  dbdriver = getappdata(0, 'mysql_driver');
+  dburl    = sprintf('jdbc:mysql://%s/%s',host,db);
+
+  disp(sprintf('** Connecting to %s as %s...', host, user))
+
+  conn     = database(db,user,pw,dbdriver,dburl);
+  disp('** Connection status:')
+  disp(ping(conn))
+  
+  
+end
+