(编辑:jimmy 日期: 2024/11/20 浏览:2)
mysql 之通过配置文件链接数据库
配置文件jdbc.properties
##MySQL driver=com.mysql.jdbc.Driver url=jdbc\:mysql\:///ake"htmlcode">package Studying.d15; import java.io.FileInputStream; import java.sql.Connection; import java.sql.DriverManager; import java.util.Properties; public class ConnUtils { private static Connection con = null; static{ try { Properties p = new Properties(); p.load( new FileInputStream("jdbc.properties") ); String driver = p.getProperty("driver"); String url = p.getProperty("url"); String username = p.getProperty("username"); String password = p.getProperty("password"); System.out.println(url+","+driver); Class.forName(driver); con = DriverManager.getConnection(url, username, password); } catch (Exception e) { e.printStackTrace(); } } public static Connection getConnection(){ return con; } }以上就是mysql 之通过配置文件链接数据库的实例详解,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!