• 大小: 4.67MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-11
  • 语言: Java
  • 标签: Java  Web  Angular  数据库  H2  

资源简介

这是一个Web版本的数据库连接工具,使用Java+Angular开发,

资源截图

代码片段和文件信息

package com.tntxia.dbconn;

import java.util.HashMap;
import java.util.Map;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import com.tntxia.dbmanager.DBManager;
import com.tntxia.dbmanager.datasource.DefaultDataSource;
import com.tntxia.web.util.DatasourceStore;

public class RegisterPool {

private static DBManager dbManager = new DBManager(DatasourceStore.getDatasource(“default“));

private static Map pool = new HashMap();

// 当前连接的ID
public static String currentConnId;

public static void register(String key) throws Exception{
currentConnId = key;
DataSource dataSource = pool.get(key);
if(dataSource!=null){
return;
}
String sql = “select * from connect_info where id =?“;
Mapject> map = dbManager.queryForMap(sql new object[]{key}true);
if(map==null){
throw new Exception(“连接不存在!!“);
}

String db_type = (String) map.get(“db_type“);
String url = (String) map.get(“url“);

if(“jndi“.equals(db_type)){

DataSource ds=null;
try
    {
        // 初始化查找命名空间
        Context ctx = new InitialContext();
        // 找到DataSource
        ds = (DataSource)ctx.lookup(url);
       
    }
    catch(Exception e)
    {
        System.out.println(e);
    }
pool.put(key ds);
}else{
String driver = (String) map.get(“driver“);

String username = (String) map.get(“username“);
String password = (String) map.get(“password“);
DefaultDataSource defaultdataSource = new DefaultDataSource();
defaultdataSource.setDriverClassName(driver);
defaultdataSource.setUrl(url);
defaultdataSource.setUsername(username);
defaultdataSource.setPassword(password);
pool.put(key defaultdataSource);
}
}

public static DataSource getCurrentDataSource(){
return pool.get(currentConnId);
}

public static DataSource getDataSource(String connid) throws Exception{

DataSource res = pool.get(connid);

if(res==null){
register(connid);
res = pool.get(connid);
}


return res;
}



}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-15 11:54  DBConnector\
     文件        2469  2017-04-02 12:58  DBConnector\.classpath
     文件        1044  2016-08-06 00:34  DBConnector\.project
     目录           0  2017-01-14 23:07  DBConnector\.settings\
     文件         503  2016-08-06 00:34  DBConnector\.settings\.jsdtscope
     文件         187  2017-04-03 03:37  DBConnector\.settings\org.eclipse.core.resources.prefs
     文件         670  2017-04-02 12:58  DBConnector\.settings\org.eclipse.jdt.core.prefs
     文件         461  2016-08-06 00:34  DBConnector\.settings\org.eclipse.wst.common.component
     文件         305  2017-04-02 12:55  DBConnector\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2016-08-06 00:34  DBConnector\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2016-08-06 00:34  DBConnector\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2017-01-15 11:54  DBConnector\build\
     文件          36  2017-05-21 20:41  DBConnector\build.properties
     文件        1338  2016-08-06 12:42  DBConnector\build.xml
     目录           0  2017-08-12 12:27  DBConnector\build\classes\
     目录           0  2017-08-12 12:27  DBConnector\build\classes\com\
     目录           0  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\
     目录           0  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\
     目录           0  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\
     文件        4072  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\DBConnectorAction.class
     文件        3263  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\ExecuteAction.class
     文件        1875  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\FileChooseAction.class
     文件         872  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\HistoryAction.class
     目录           0  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\mvc\
     文件        1616  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\mvc\IndexAction.class
     文件        1891  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\action\RegisterAction.class
     目录           0  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\bean\
     文件         942  2017-08-12 12:27  DBConnector\build\classes\com\tntxia\dbconn\bean\FileBean.class
     文件        3026  2017-08-14 19:22  DBConnector\build\classes\com\tntxia\dbconn\RegisterPool.class
     文件          82  2016-06-07 21:28  DBConnector\build\classes\jdbc.properties
     文件         328  2016-06-06 20:59  DBConnector\build\classes\log4j.properties
............此处省略97个文件信息

评论

共有 条评论