Import java.io.IOException; Import Java.io.InputStream; Import java.util.Properties; Import Java.sql.DriverManager; Import java.sql.SQLException; Import com.mysql.jdbc.Connection; Public class jdbctools { Public jdbctools () { } Public staticConnection getconnection () throws IOException, SQLException { Connection conn = null; Properties Properties = new properties (); InputStream instream = jdbctools. class . getClassLoader () . getResourceAsStream ("jdbc.properties"); properties. Load (instream); String User = properties. GetProperty ("user"); String Password = properties. GetProperty ("password"); String driverclass = properties. GetProperty ("Driverclass"); String Jdbcurl = properties. GetProperty ("Jdbcurl"); conn = (Connection) DriverManager. Getconnection(jdbcurl,user,password); returnconn; } Public staticvoid main (string[] args) throws IOException, SQLException { System. out. println (getconnection()); } } |