一台服务器上的sqlserver数据库,里面有如下数据库:A_2012,A2013,B_2012,B_2013,C_2012,C_2013.....
用的是SSH框架,操作是:在下拉中先选择一个字母,再选择一个年份,然后根据我选择的这些参数查询对应的数据库。
现在的问题是拼接好数据库名后,在当前这个框架中用什么方式来连接数据库比较好
有没好点的解决方案mssqlserver
用的是SSH框架,操作是:在下拉中先选择一个字母,再选择一个年份,然后根据我选择的这些参数查询对应的数据库。
现在的问题是拼接好数据库名后,在当前这个框架中用什么方式来连接数据库比较好
有没好点的解决方案mssqlserver
解决方案 »
- 求指点啊!root账号在mysql中show processlist,但发现连接数竟然小于C3P0连接池的最小连接数, 费解啊,求指点!
- Spring的AOP技术实现权限管理
- java.lang.NullPointerException
- jsp调用applet生成jfreechart图像的异常
- javamail发送邮件时,自己的邮箱(163.com,qq.com)证明会失败.为什么?
- The value for the useBean class attribute xnc.db.query.DBQuery is invalid.
- 使用Xfire开发Web service-----csdn中就没有会的!!!!!!!!!!!!!!!!
- 一个用Action写文件的问题
- 请前辈提点:linux下配java web服务器问题
- 去除文本所有行数前缀空行
- Spring 提取注解@RequestMapping配置的URL
- 上传得到的都是.tmp的文件?
* 变换数据源
*/
public static Boolean changeDataSource(Map map) {
DriverManagerDataSource basicDS = (DriverManagerDataSource) createBean("dataSourceTrends"); basicDS.setUsername((String) map.get("sa"));
basicDS.setPassword((String) map.get("password"));
String url = "jdbc:sqlserver://" + (String) map.get("ip") + ":"
+ (String) map.get("port") + ";DatabaseName="
+ (String) map.get("DatabaseName"); basicDS.setUrl(url);
// if("420684".equals((String)map.get("areacode"))){
// basicDS.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//sql2005
// }else{
// basicDS.setDriverClassName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//sql2000
// }
Boolean isCon;
try {
// isCon = basicDS.getConnection();
// int is = basicDS.getLoginTimeout();
// System.out.println("is :"+ is);
System.out.println(url);
if (basicDS.getConnection() != null)
System.out.println("-----ds------"); } catch (SQLException e) { FileWriter fileWriter = null;
PrintWriter printWriter = null;
Date now = new Date();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG);
// DateFormat d1 = DateFormat.getDateInstance();
// //默认语言(汉语)下的默认风格(MEDIUM风格,比如:2008-6-16 20:54:53)
try {
fileWriter = new FileWriter("e:/4201/DBConnectLog.txt", true);
printWriter = new PrintWriter(fileWriter);
printWriter.println(df.format(now) + "--:" + url + " 没有连接上");
printWriter.close();
fileWriter.close();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (printWriter != null) {
printWriter.close();
}
if (fileWriter != null) {
try {
fileWriter.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return false; }
return true; }
public static Object createBean(String beanid) {
ApplicationContext ctx = ApplicationContextLoader.getAppContext();
return ctx.getBean(beanid);
}