java 访问sqlserver慢_JDBC 远程 SQLSERVER 速度很慢的处理方式
1、数据库连接配置
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc:sqlserver://172.16.253.122:1433;DatabaseName=joytone;
sa
class="com.ztkj.his.mzregister.server.dao.jdbc.impl.NetpreLgfyDaoJdbcImpl" >
2、访问 sqlserver 代码
public List getYuyueInfo(String orderno, String cardno) throws DaoException {
GlobalFun.logIn();
List list = null;
try {
String sql = "SELECT * FROM JOYTONE_YUYUE where 1=1 ";
if (!Assert.isNull(orderno)) {
sql = sql.concat(" and order_no='").concat(orderno).concat("'");
} else if ((!Assert.isNull(cardno)) && cardno.length() > 0) {
sql = sql.concat(" and his_member_id='").concat(cardno).concat("'");
}
sql = sql.concat(" order by order_no desc ");
logger.info("orderno=" + orderno + ",cardno=" + cardno);
logger.debug(sql);
list = this.getJdbcTemplate().query(sql, new ObjectMapper(JoytoneYuyue.class));
} catch (Exception e) {
throw new DaoException(e.getMessage());
}
GlobalFun.logOut();
return list;
}
3、解决办法
在 web 服务器 c:\windows\system32\drivers\etc\HOSTS表中添加一条
172.16.253.122172.16.253.122
问题原因:servername(本例中是172.116.253.122),程序访问172.116.253.122时,把它当成机器名称进行解析,长时间没有结果最后才访问IP为172.116.253.122的机器。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)