AI智能
改变未来

IDEA连接MySQL的通用代码

@Testpublic void testConnection5() throws Exception {//1.加载配置文件//Class_01为当前类名InputStream is = Class_01.class.getClassLoader().getResourceAsStream(\"jdbc.properties\");Properties pros = new Properties();pros.load(is);//2.读取配置信息String user = pros.getProperty(\"user\");String password = pros.getProperty(\"password\");String url = pros.getProperty(\"url\");String driverClass = pros.getProperty(\"driverClass\");//3.加载驱动Class.forName(driverClass);// 4.获取连接Connection conn = DriverManager.getConnection(url,user,password);System.out.println(conn);}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » IDEA连接MySQL的通用代码