Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you can set connection information(db Name,password,server Address,etc...) in .properties file. LIKE below.</p> <p>1)static way <strong>config.properties</strong>(generally it created at classPath-src\config.properties) file contains</p> <pre><code>driver=com.mysql.jdbc.Driver database=jdbc:mysql://localhost:3306/dbName dbuser=root dbpassword=root </code></pre> <p>you can also create or reset value</p> <p>or <strong>1)create or set dynamic properties file.</strong></p> <pre><code>import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class App { public static void main( String[] args ) { Properties prop = new Properties(); try { //set the properties value prop.setProperty("database", "localhost"); prop.setProperty("dbuser", "patel"); prop.setProperty("dbpassword", "password"); //save properties to project root folder prop.store(new FileOutputStream("config.properties"), null); } catch (IOException ex) { ex.printStackTrace(); } } } </code></pre> <p>output in (config.properties)</p> <pre><code> dbpassword=password database=localhost dbuser=patel </code></pre> <p><strong>2)now time to read it at runtime.</strong></p> <pre><code>import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class App { public static void main( String[] args ) { Properties prop = new Properties(); try { //load a properties file prop.load(new FileInputStream("config.properties")); //get the property value and print it out System.out.println(prop.getProperty("database")); System.out.println(prop.getProperty("dbuser")); System.out.println(prop.getProperty("dbpassword")); } catch (IOException ex) { ex.printStackTrace(); } } } </code></pre> <p>output</p> <pre><code>localhost patel password </code></pre> <p>pls write this code in jsp in &lt;% %> this way u can load any thing at run time. need any help ping me..................:)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload