[Tbase-cvs] tbase-runtime/src/org/tbase/sql TBaseDatabase.java,NONE,1.1 TBaseRecordset.java,NONE,1.1
Status: Alpha
Brought to you by:
ron_bakker
|
From: Ron B. <ron...@us...> - 2006-03-27 06:07:46
|
Update of /cvsroot/tbase/tbase-runtime/src/org/tbase/sql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21589/src/org/tbase/sql Added Files: TBaseDatabase.java TBaseRecordset.java Log Message: Partial Service/SQL implementation --- NEW FILE: TBaseDatabase.java --- /* * TBase Runtime * Copyright (C) 2006 Ron Bakker * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * E-Mail the project team at: tba...@li... * */ package org.tbase.sql; import java.sql.*; import java.util.*; /** * @author Ron Bakker * @version $Id: TBaseDatabase.java,v 1.1 2006/03/27 06:07:35 ron_bakker Exp $ */ public class TBaseDatabase { private Connection m_connection; public boolean Connect(String driver, String connectionstring, Properties connectionproperties) { try { Class.forName(driver); } catch( ClassNotFoundException e ) { System.out.println("Could not load: "+driver); return false; } String connect_string = new String("jdbc:"+connectionstring); Properties connect_properties = new Properties(connectionproperties); try { m_connection = DriverManager.getConnection(connect_string, connect_properties); } catch (SQLException e) { System.out.println("Could not connect to: "+connectionstring); return false; } return true; } public TBaseRecordset Query(String query) { try { Statement statement = m_connection.createStatement(); ResultSet resultset = statement.executeQuery(query); return new TBaseRecordset(resultset); } catch (SQLException e) { return null; } } } --- NEW FILE: TBaseRecordset.java --- /* * TBase Runtime * Copyright (C) 2006 Ron Bakker * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * E-Mail the project team at: tba...@li... * */ package org.tbase.sql; import java.sql.*; import java.util.*; /** * @author Ron Bakker * @version $Id: TBaseRecordset.java,v 1.1 2006/03/27 06:07:35 ron_bakker Exp $ */ public class TBaseRecordset { private ResultSet m_resultset; private Hashtable<String, Object> m_row = new Hashtable<String, Object>(); public TBaseRecordset(ResultSet resultset) { m_resultset = resultset; } public boolean Fetch() { try { boolean rval = m_resultset.next(); m_row.clear(); if (rval) _mapResultRow(); return rval; } catch ( SQLException e ) { return false; } } private void _mapResultRow() { try { ResultSetMetaData metadata = m_resultset.getMetaData(); int nColumns = metadata.getColumnCount(); for (int i=1; i<=nColumns; i++) { String name = metadata.getColumnLabel(i).toUpperCase(); Object value = m_resultset.getObject(i); m_row.put(name, value); } } catch ( SQLException e ) { } } public Object getValue(String objName) { return m_row.get(objName.toUpperCase()); } } |