1 package wrappers; 2 3 import java.sql.*; 4 import java.util.Hashtable; 5 6 import javax.sql.DataSource; 7 import com.mysql.cj.jdbc.MysqlDataSource; 8 9 public class MysqlInterface extends JdbcInterface { MysqlInterface()10 public MysqlInterface() { 11 this(true); 12 } // end of default constructor 13 MysqlInterface(boolean b)14 public MysqlInterface(boolean b) { 15 super(b); 16 17 if (dst == null) 18 dst = new Hashtable<String, DataSource>(); 19 20 } // end of default constructor 21 22 @Override JdbcConnect(String[] parms, int fsize, boolean scrollable)23 public int JdbcConnect(String[] parms, int fsize, boolean scrollable) { 24 int rc = 0; 25 String url = parms[1]; 26 DataSource ds = null; 27 MysqlDataSource mds = null; 28 29 if (DEBUG) 30 System.out.println("Connecting to MySQL data source"); 31 32 try { 33 CheckURL(url, "mysql"); 34 35 if ((ds = dst.get(url)) == null) { 36 mds = new MysqlDataSource(); 37 mds.setUrl(url); 38 39 if (parms[2] != null) 40 mds.setUser(parms[2]); 41 42 if (parms[3] != null) 43 mds.setPassword(parms[3]); 44 45 ds = mds; 46 47 dst.put(url, ds); 48 } // endif ds 49 50 // Get a connection from the data source 51 conn = ds.getConnection(); 52 53 // Get the data base meta data object 54 dbmd = conn.getMetaData(); 55 56 // Get a statement from the connection 57 stmt = GetStmt(fsize, scrollable); 58 } catch (SQLException se) { 59 SetErrmsg(se); 60 rc = -2; 61 } catch( Exception e ) { 62 SetErrmsg(e); 63 rc = -3; 64 } // end try/catch 65 66 return rc; 67 } // end of JdbcConnect 68 69 } // end of class MysqlInterface 70