2 回答
TA贡献1824条经验 获得超8个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | String driverName = "com.mysql.jdbc.Driver"; // 加载JDBC驱动 String dbURL = "jdbc:mysql://localhost:3306/test"; // 连接服务器和数据库test String userName = "sa"; // 默认用户名 String userPwd = "sa"; // 密码 java.sql.Connection dbConn;
try { Class.forName(driverName).newInstance(); dbConn = java.sql.DriverManager.getConnection(dbURL, userName, userPwd); System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful! } catch (ClassNotFoundException e) { System.out.println("没有找到驱动"); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } |
TA贡献1942条经验 获得超3个赞
<bean id="dalClient" class="com.suning.framework.dal.client.support.DefaultDalClient">
<!-- 数据源路由配置 -->
<!-- <property name="rules">
<map>
<entry key="route.userId > 0 && route.userId < 50"
value-ref="dataSourceForOrderOne" />
<entry key="route.userId>=50 && route.userId<100"
value-ref="dataSourceForOrderTwo" />
</map>
</property> -->
<!-- SQL的Xml配置路径 -->
<property name="resources" value="classpath*:conf/sqlMap/sqlMap_*.xml" />
<!-- 定义默义的数据源 -->
<property name="defaultDataSource" ref="dataSource" />
</bean>
添加回答
举报