Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Connection Information to DB in Java Web ?

Connection Information to DB in Java Web ?

Scheduled Pinned Locked Moved Java
databasejavasql-serversysadminhelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tannghia
    wrote on last edited by
    #1

    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 !

    L J A 3 Replies Last reply
    0
    • T tannghia

      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 !

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      tannghia wrote:

      But I cann't read information from "WebConfig" because I don't know it's directory.

      I assume you mean that you want to store this file on the client system, which I do not think is allowed.

      The best things in life are not things.

      1 Reply Last reply
      0
      • T tannghia

        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 !

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Files exist on file systems. You can't find a file unless you know its location on the file system. There is no other option. There are options as to how one might locate configuration files relative to an application or via a configuration path.

        1 Reply Last reply
        0
        • T tannghia

          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 !

          A Offline
          A Offline
          all_in_flames
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups