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. .properties file added to database

.properties file added to database

Scheduled Pinned Locked Moved Java
tutorialdatabasequestion
15 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.
  • P Offline
    P Offline
    pancakeleh
    wrote on last edited by
    #1

    Hello i have 3 properties file consisting of information. Is it possible for me to add the information of 3 properties files into database and instead of getting properties from the properties file, i get the values from the database? however i have no idea on how to start anyone could guide me?

    D T 2 Replies Last reply
    0
    • P pancakeleh

      Hello i have 3 properties file consisting of information. Is it possible for me to add the information of 3 properties files into database and instead of getting properties from the properties file, i get the values from the database? however i have no idea on how to start anyone could guide me?

      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      Create a table to hold the data that is currently in the properties file (one table for each properties file is the easiest option). Insert the data into the table. Read the data using a SQL select statement. Your table structure can be very simple: two columns, key, value. That's basically it.

      P 1 Reply Last reply
      0
      • P pancakeleh

        Hello i have 3 properties file consisting of information. Is it possible for me to add the information of 3 properties files into database and instead of getting properties from the properties file, i get the values from the database? however i have no idea on how to start anyone could guide me?

        T Offline
        T Offline
        TorstenH
        wrote on last edited by
        #3

        ...you will at least need one properties file defining the database for your application. You can set up the properties in a folder aside the source:

        - Source "src"

        • Resources "res"
          • "images"
          • "properties"
            • "database"
            • "application"
          • ....

        And it is possible to add encryption to them. regards Torsten

        I never finish anyth...

        1 Reply Last reply
        0
        • D David Skelly

          Create a table to hold the data that is currently in the properties file (one table for each properties file is the easiest option). Insert the data into the table. Read the data using a SQL select statement. Your table structure can be very simple: two columns, key, value. That's basically it.

          P Offline
          P Offline
          pancakeleh
          wrote on last edited by
          #4

          i am doing it in a .java file in netbeans however there is error when i try to connect to the database.. my profiles file includes the following as shown below: yahoo=http://yahoo.com google=http://google.com so i still use the key and value for my table?

          modified on Monday, January 24, 2011 10:59 PM

          L D 2 Replies Last reply
          0
          • P pancakeleh

            i am doing it in a .java file in netbeans however there is error when i try to connect to the database.. my profiles file includes the following as shown below: yahoo=http://yahoo.com google=http://google.com so i still use the key and value for my table?

            modified on Monday, January 24, 2011 10:59 PM

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

            pancakeleh wrote:

            however there is error when i try to connect to the database.

            Maybe if you show what that error is people will be able to make some suggestions.

            I must get a clever new signature for 2011.

            1 Reply Last reply
            0
            • P pancakeleh

              i am doing it in a .java file in netbeans however there is error when i try to connect to the database.. my profiles file includes the following as shown below: yahoo=http://yahoo.com google=http://google.com so i still use the key and value for my table?

              modified on Monday, January 24, 2011 10:59 PM

              D Offline
              D Offline
              David Skelly
              wrote on last edited by
              #6

              Yes, you can pick up the value you want from the table with a sql command something like:

              SELECT value FROM MyTable WHERE key = 'yahoo'

              That would do it. NB, key may be a reserved keyword depending on the particular database you are using. Just give that column whatever name is convenient instead if that is the case. As Richard has pointed out, if you let us know the problem you are having when you try to connect to the database we might be able to help a bit more.

              P 1 Reply Last reply
              0
              • D David Skelly

                Yes, you can pick up the value you want from the table with a sql command something like:

                SELECT value FROM MyTable WHERE key = 'yahoo'

                That would do it. NB, key may be a reserved keyword depending on the particular database you are using. Just give that column whatever name is convenient instead if that is the case. As Richard has pointed out, if you let us know the problem you are having when you try to connect to the database we might be able to help a bit more.

                P Offline
                P Offline
                pancakeleh
                wrote on last edited by
                #7

                the code as shown below: http://img96.imageshack.us/img96/4586/errorwv.png[^] I have added the imports but however i am facing errors.

                T L D 3 Replies Last reply
                0
                • P pancakeleh

                  the code as shown below: http://img96.imageshack.us/img96/4586/errorwv.png[^] I have added the imports but however i am facing errors.

                  T Offline
                  T Offline
                  TorstenH
                  wrote on last edited by
                  #8

                  WHICH ERRORS? Do you actually have errors while running the code - I mean this red text running in that little fancy window below your code - you know? Is it to much to ask for copying it in here? Otherwise we can just tell you that we're also sometimes "facing errors" regards Torsten

                  I never finish anyth...

                  1 Reply Last reply
                  0
                  • P pancakeleh

                    the code as shown below: http://img96.imageshack.us/img96/4586/errorwv.png[^] I have added the imports but however i am facing errors.

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

                    Once again you seem to be trying to build an application line by line without spending some time reading the documentation and getting a grasp of the fundamentals. Take a look here[^] at the Java API documentation and check the requirements of the features you are trying to use.

                    I must get a clever new signature for 2011.

                    1 Reply Last reply
                    0
                    • P pancakeleh

                      the code as shown below: http://img96.imageshack.us/img96/4586/errorwv.png[^] I have added the imports but however i am facing errors.

                      D Offline
                      D Offline
                      David Skelly
                      wrote on last edited by
                      #10

                      You are not handling the exceptions these JDBC methods throw. You should take some time to learn the basics of JDBC programming. There are plenty of good books available, and lots of on-line tutorials if you cannot afford a book.

                      P 1 Reply Last reply
                      0
                      • D David Skelly

                        You are not handling the exceptions these JDBC methods throw. You should take some time to learn the basics of JDBC programming. There are plenty of good books available, and lots of on-line tutorials if you cannot afford a book.

                        P Offline
                        P Offline
                        pancakeleh
                        wrote on last edited by
                        #11

                        i have got it. As previously i am using the properties file to get Property and i have this getProperty method as shown below:

                        public static String getProperties(String inputProperty) {
                        Properties props = new Properties();
                        try {
                        try {
                        // Set the directory and the file name.
                        props.load(Class.forName("......autoMessage").getResourceAsStream("autoMessage.properties"));
                        } catch (ClassNotFoundException ex) {
                        Logger.getLogger(autoMessage.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        } catch (IOException ex) {
                        Logger.getLogger(autoMessage.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        String output = props.getProperty(inputProperty);
                        return output;
                        }

                        Do i have to create a method in order to get the value from the database?

                        D 1 Reply Last reply
                        0
                        • P pancakeleh

                          i have got it. As previously i am using the properties file to get Property and i have this getProperty method as shown below:

                          public static String getProperties(String inputProperty) {
                          Properties props = new Properties();
                          try {
                          try {
                          // Set the directory and the file name.
                          props.load(Class.forName("......autoMessage").getResourceAsStream("autoMessage.properties"));
                          } catch (ClassNotFoundException ex) {
                          Logger.getLogger(autoMessage.class.getName()).log(Level.SEVERE, null, ex);
                          }
                          } catch (IOException ex) {
                          Logger.getLogger(autoMessage.class.getName()).log(Level.SEVERE, null, ex);
                          }
                          String output = props.getProperty(inputProperty);
                          return output;
                          }

                          Do i have to create a method in order to get the value from the database?

                          D Offline
                          D Offline
                          David Skelly
                          wrote on last edited by
                          #12

                          I'm afraid the best advice I can give you is to:

                          • Read up about Exception handling
                          • Read up about Properties
                          • Read up about JDBC and database programming

                          I get the feeling you are trying to teach yourself Java, which is admirable but you seem to be missing some basic grounding. A good book would help. Many people here would be happy to recommend one. In your code above: you don't need to nest try blocks in the way you have done, you can have multiple catch statements for a single try. Also, it's probably inefficient to load the Properties every time you come to get a property, you can load them once up front. I have no idea what your question about creating a method to get the value from the database means. Basically what you need to do is load the properties from the database instead of loading from a properties file.

                          P L 2 Replies Last reply
                          0
                          • D David Skelly

                            I'm afraid the best advice I can give you is to:

                            • Read up about Exception handling
                            • Read up about Properties
                            • Read up about JDBC and database programming

                            I get the feeling you are trying to teach yourself Java, which is admirable but you seem to be missing some basic grounding. A good book would help. Many people here would be happy to recommend one. In your code above: you don't need to nest try blocks in the way you have done, you can have multiple catch statements for a single try. Also, it's probably inefficient to load the Properties every time you come to get a property, you can load them once up front. I have no idea what your question about creating a method to get the value from the database means. Basically what you need to do is load the properties from the database instead of loading from a properties file.

                            P Offline
                            P Offline
                            pancakeleh
                            wrote on last edited by
                            #13

                            yeah you are right i am learning java on my own and my only hope is in here. Hope you guys will understand if i asked something really simple. Yes what i want to do is load the properties from the database instead of loading from a properties file. I have 3 properties files in the project. I manage to change 2 of them and still have 1 not done yet. I came across this problem for the third file. It is a .java file. My code as shown below:

                            public class emailNotification {

                            private static final String SMTP\_HOST\_NAME = getProperties("SMTP\_HOST\_NAME");
                            private static final int SMTP\_HOST\_PORT = Integer.parseInt(getProperties("SMTP\_HOST\_PORT"));
                            private static final String SMTP\_AUTH\_USER = getProperties("SMTP\_AUTH\_USER");
                            private static final String SMTP\_AUTH\_PWD = getProperties("SMTP\_AUTH\_PWD");
                            
                            private emailNotification() {
                            
                            }
                            

                            I am unable to create a database connection in the public class even after i did the try and catch. Any idea how shld i do this? another question to ask:

                                    Properties props = new Properties();
                                    props.put("mail.transport.protocol", "smtps");
                            

                            The above code is to create a new property right? is it appropriate for me to use in my case whereby i will load the properties from the database instead of loading from a properties file.

                            modified on Thursday, January 27, 2011 1:39 AM

                            D 1 Reply Last reply
                            0
                            • P pancakeleh

                              yeah you are right i am learning java on my own and my only hope is in here. Hope you guys will understand if i asked something really simple. Yes what i want to do is load the properties from the database instead of loading from a properties file. I have 3 properties files in the project. I manage to change 2 of them and still have 1 not done yet. I came across this problem for the third file. It is a .java file. My code as shown below:

                              public class emailNotification {

                              private static final String SMTP\_HOST\_NAME = getProperties("SMTP\_HOST\_NAME");
                              private static final int SMTP\_HOST\_PORT = Integer.parseInt(getProperties("SMTP\_HOST\_PORT"));
                              private static final String SMTP\_AUTH\_USER = getProperties("SMTP\_AUTH\_USER");
                              private static final String SMTP\_AUTH\_PWD = getProperties("SMTP\_AUTH\_PWD");
                              
                              private emailNotification() {
                              
                              }
                              

                              I am unable to create a database connection in the public class even after i did the try and catch. Any idea how shld i do this? another question to ask:

                                      Properties props = new Properties();
                                      props.put("mail.transport.protocol", "smtps");
                              

                              The above code is to create a new property right? is it appropriate for me to use in my case whereby i will load the properties from the database instead of loading from a properties file.

                              modified on Thursday, January 27, 2011 1:39 AM

                              D Offline
                              D Offline
                              David Skelly
                              wrote on last edited by
                              #14

                              pancakeleh wrote:

                              I am unable to create a database connection in the public class even after i did the try and catch.

                              What have you tried? If you read the tutorial on JDBC it shows you how to create a database connection. I am not a mind-reader, so I have no idea why you are having a problem unless you give us some more information.

                              pancakeleh wrote:

                              The above code is to create a new property right? is it appropriate for me to use in my case whereby i will load the properties from the database instead of loading from a properties file.

                              Yes, this is pretty much it. In pseudo-code you would do something like:

                              • Connect to the database
                              • Get the properties from the database using a SELECT statement
                              • Iterate over the result set
                              • For each row in the result set, add key/value into the properties map
                              • Close database connection

                              That's roughly it.

                              1 Reply Last reply
                              0
                              • D David Skelly

                                I'm afraid the best advice I can give you is to:

                                • Read up about Exception handling
                                • Read up about Properties
                                • Read up about JDBC and database programming

                                I get the feeling you are trying to teach yourself Java, which is admirable but you seem to be missing some basic grounding. A good book would help. Many people here would be happy to recommend one. In your code above: you don't need to nest try blocks in the way you have done, you can have multiple catch statements for a single try. Also, it's probably inefficient to load the Properties every time you come to get a property, you can load them once up front. I have no idea what your question about creating a method to get the value from the database means. Basically what you need to do is load the properties from the database instead of loading from a properties file.

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

                                I have made the same suggestion a number of times, even providing links to the tutorial pages, but he/she still keeps coming back with similar questions. I hope s/he's not getting paid for this.

                                I must get a clever new signature for 2011.

                                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