Mercurial > hg > openmind
view src/main/java/org/mpi/openmind/scripts/DBUtils.java @ 8:478fd6f26ea8
(none)
author | jurzua |
---|---|
date | Tue, 24 Feb 2015 10:45:45 +0000 |
parents | |
children |
line wrap: on
line source
package org.mpi.openmind.scripts; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.naming.spi.DirStateFactory.Result; public class DBUtils { private static String DB_URL = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8"; public static Connection getConn(String mysqlUser, String mysqlPwd){ Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection(DB_URL, mysqlUser, mysqlPwd); return conn; } catch (ClassNotFoundException ex) { System.err.println(ex.getMessage()); } catch (IllegalAccessException ex) { System.err.println(ex.getMessage()); } catch (InstantiationException ex) { System.err.println(ex.getMessage()); } catch (SQLException ex) { System.err.println(ex.getMessage()); } return conn; } public static ResultSet getDefinition(Connection conn, String oc) throws SQLException{ String query = "select * from node where node_type = 'ENTITY' and object_class = 'TBox' and own_value = '" + oc + "'"; Statement stmt = conn.createStatement(); return stmt.executeQuery(query); } public static Long getDefId(Connection conn, String oc) throws SQLException{ ResultSet rs = getDefinition(conn, oc); if(rs != null && rs.next()) return rs.getLong("id"); return null; } public static ResultSet getDefAtts(Connection conn, String oc, String attName) throws SQLException{ Long defId = getDefId(conn, oc); String query = "select * from node where " + "node_type = 'ATTRIBUTE' and " + "object_class = 'TBox' and " + "source_id = '" + defId + "' and " + "own_value = '" + attName + "'"; Statement stmt = conn.createStatement(); return stmt.executeQuery(query); } public static void getAtt(String oc, String attName){ String query = "select * from node where node_type = 'ATTRIBUTE' and source_obj_class = 'WITNESS' and object_class = 'notes'"; } }