📄 sqlconnection.java
字号:
package org.huihoo.openweb.uddiserver.util;import java.sql.*;import java.net.URL;import java.util.*;import java.io.*;/** * SqlConnection.java * * * @author <a href="mailto:powertyrael@163.net">Darth Vader</a> and <a href="mailto:13975192956@hnmcc.com">Spring</a> create at 20:46:06 on 2003-5-6 * * @version 1.0 alpha */public class SqlConnection{ static Connection con = null; public Properties getProp() throws IOException { URL url = getClass().getClassLoader().getResource("conf/openwebuddi.config"); Properties props = new Properties(); if(url==null) throw new IOException("openwebuddi.config not found"); props.load(url.openStream()); return props; } static public Connection getConnection() throws SQLException, ClassNotFoundException, IOException { SqlConnection sql = new SqlConnection(); String url=""; String user=""; String passwd=""; Properties props; props = sql.getProp(); Class.forName(props.getProperty("Class")); url = props.getProperty("URL"); user = props.getProperty("user"); passwd =props.getProperty("passwd"); return DriverManager.getConnection(url,user,passwd); } public static String getUserIdfromBindingKey( String bindingKey) throws SQLException, ClassNotFoundException, IOException { String sKey = getServiceKeyfromBindingKey( bindingKey); if( sKey == null) return null; String bKey = getBusinessKeyfromServiceKey( sKey); if( bKey == null) return null; return getUserIdfromBusinessKey( bKey); } public static String getUserIdfromServiceKey( String serviceKey) throws SQLException, ClassNotFoundException, IOException { String bKey = getBusinessKeyfromServiceKey( serviceKey); if( bKey == null) return null; return getUserIdfromBusinessKey( bKey); } public static String getUserIdfromTModelKey( String tmodelKey) throws SQLException, ClassNotFoundException, IOException { if( con == null) con = getConnection(); Statement stmt = con.createStatement(); String query = "SELECT userid from TModelDetails where tmodelkey = '" + tmodelKey + "'"; ResultSet rs = stmt.executeQuery( query); String userid = null; while ( rs.next()){ userid = rs.getString("userid"); } stmt.close(); return userid; } public static String getServiceKeyfromBindingKey( String bindingKey) throws SQLException, ClassNotFoundException, IOException { if( con == null) con = getConnection(); Statement stmt = con.createStatement(); String query = "SELECT servicekey from BindingTemplate where bindingkey = '" + bindingKey + "'"; ResultSet rs = stmt.executeQuery( query); String key = null; while ( rs.next()){ key = rs.getString("servicekey"); } stmt.close(); return key; } public static String getBusinessKeyfromServiceKey( String serviceKey) throws SQLException, ClassNotFoundException, IOException { if( con == null) con = getConnection(); Statement stmt = con.createStatement(); String query = "SELECT businesskey from BusinessService where servicekey = '" + serviceKey + "'"; ResultSet rs = stmt.executeQuery( query); String key = null; while ( rs.next()){ key = rs.getString("businesskey"); } stmt.close(); return key; } public static String getUserIdfromBusinessKey( String businessKey) throws SQLException, ClassNotFoundException, IOException { if( con == null) con = getConnection(); Statement stmt = con.createStatement(); String query = "SELECT userid from BusinessDetails where businesskey = '" + businessKey + "'"; ResultSet rs = stmt.executeQuery( query); String userid = null; while ( rs.next()){ userid = rs.getString("userid"); } stmt.close(); return userid; } //This function finds out if a given value exists in a given table or not. public static boolean isPresent(String tableName, String keyName, String keyValue) throws SQLException, ClassNotFoundException, IOException { if( con == null) con = getConnection(); Statement stmt = con.createStatement(); String query = "SELECT * from "+tableName+" where "+keyName+ " = '" + keyValue + "'"; ResultSet rs = stmt.executeQuery( query); if ( rs.next()){ stmt.close(); return true; } stmt.close(); return false; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -