首页 文章

SAP HANA数据库连接在控制台应用程序中运行良好,但同样的事情不适用于服务

提问于
浏览
0

SAP HANA数据库连接在控制台应用程序中工作正常,但是当从服务或Web应用程序调用时,同样的事情不起作用 . 显示错误,如没有合适的驱动程序 . 我添加了ngdbc.jar . 我使用过Websphere8.5服务器和java 1.6

Class.forName("com.sap.db.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:sap://hostname:30015/?autocommit=false&user=myuser&password=mypassword");

1 回答

  • 0

    不要强调上述观点,你的JDK将在2018年4月停止服务,考虑现在转向Java 8 . 当你说"DB connection works fine in console application"我假设你的意思是你're able to test the connection from the console successfully. From the snippet you pasted, the reason your application is failing is that you'没有使用数据源,你've configured in WAS and that is being used by the test connection. Instead, you'试图直接访问DriverManager,它将绕过配置为直接加载这些类的服务器's management of JDBC, including connection and statement pooling. The class is failing to load because the application classpath isn't . Java EE应用程序通常会通过resource-ref,@ Datasource或其他方式将您在WAS中配置的数据源注入到您的应用程序中 . 这个SO post解释了数据源和DriverManager之间的区别 .

相关问题