Connection Information to DB in Java Web ?
-
I want to store connection information to Database (username, password, port ) into a file named "WebConfig". Then I create a java class named "Connect" use these information to connect to MS SQL Server. But I cann't read information from "WebConfig" because I don't know it's directory. Can you help me ? (Don't use HttpSerletContext ! ) Thanks alot !
-
I want to store connection information to Database (username, password, port ) into a file named "WebConfig". Then I create a java class named "Connect" use these information to connect to MS SQL Server. But I cann't read information from "WebConfig" because I don't know it's directory. Can you help me ? (Don't use HttpSerletContext ! ) Thanks alot !
-
I want to store connection information to Database (username, password, port ) into a file named "WebConfig". Then I create a java class named "Connect" use these information to connect to MS SQL Server. But I cann't read information from "WebConfig" because I don't know it's directory. Can you help me ? (Don't use HttpSerletContext ! ) Thanks alot !
-
I want to store connection information to Database (username, password, port ) into a file named "WebConfig". Then I create a java class named "Connect" use these information to connect to MS SQL Server. But I cann't read information from "WebConfig" because I don't know it's directory. Can you help me ? (Don't use HttpSerletContext ! ) Thanks alot !
If your Java web application is not using HttpServletContext (and by association, the rest of the Java Servlet API), there's no robust best-practice way to configure resources outside of simple property files. You can look up any file by context, if you're aware of the layout of your application (I'll assume EAR/WAR/JAR, but since you don't seem to be using JEE based on your HttpServletContext comment, that might be a flawed assumption). If you had a "resources" project, you should know where it will live in relation to your main web project: i.e. EAR file contains WAR file, which contains a WEB-INF/lib folder, which then contains the rest of your project jars. Based on this knowledge, you should be able to use the standard Java FileStream objects to load those files and read the connection properties you want to store. I would recommend researching JEE best practices for web resources, however, as there are ways to store connection information for data sources (JDBC) that follow the JEE standards, and can be used with any compatible web container (Tomcat, JBoss, IBM WebSphere, etc). Cheers!