0

I am connecting a Java program to a MySQL database, So I need the IP to connect it. Hard coding the IP is obviously a bad idea so I made a config. My only problem is I am not sure what to store the IP as in the variable. I looked around an a lot of places say int, but I don't see how that can be correct because integers don't have decimals. What should I do?

Abdul Hoque Nuri
  • 1,105
  • 1
  • 9
  • 18
  • 1
    we have to always use the String for hostname or IP address – Anil Feb 26 '19 at 11:22
  • "a lot of places say int": IPs have dots, so it seems impossible to store them as integers. If the source is reliable, provide the link – antonio Feb 26 '19 at 11:28
  • not sure why it is marked duplicate, the question is related to spring not database – Anil Feb 26 '19 at 11:28

1 Answers1

1

My only problem is I am not sure what to store the IP as in the variable

IP's/Hostnames are stored in String type variable if you are looking for data type.

There are multiple ways to configure your application level configurations. For instance, you can store in application properties file, as environment variable, as command line parameter.

application.properties

db.url="YOUR_URL"

environment variable

export DB_URL=YOUR_URL

Command Line parameter (Assuming it's a jar packaging)

java -jar -D dbUrl=YOUR_URL yourapp.jar
SSC
  • 2,956
  • 3
  • 27
  • 43