(a) The Properties class represents a persistent set of properties. Propertiescan be saved in a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.
(ii) Create properties (JDBC attribute example)
Driver=com.mysql.jdbc.driverurl=jdbc:mysql://127.0.0.1:3306/mydbuser=rootpassword =w5566
(c) Loading
Properties Props = new properties (); try {//load config file string filename = "/com/awinson/cfg/jdbc.properties"; InputStream is = th Is.getclass (). getResourceAsStream (filename);p rops.load (IS);//Connect Database Class.forName (props.getproperty ("Driver")); String url = props.getproperty ("url"); String user = Props.getproperty ("user"); String Password = props.getproperty ("password");
Connection conn = drivermanager.getconnection (URL, user, password);//Turn off autocommit, turn on transaction conn.setautocommit (false); return Conn;} catch (Exception e) {e.printstacktrace ();}
① Creating a Properties instance
② loading the configuration file to get the input stream (note the format of the path)
③ using Properties.load (inputstream) to load configuration files
④ using Properties.getproperty (String key) to get the value
Properties Java-based usage