题目内容
(4-2)importjava.sql.*;classConn{Connectionconn;publicConnectiongetConnection(){try{Class.forName("org.gjt.mm.mysql.Driver");System.out.println("数据库驱动加载成功");}catch(ClassNotFoundExceptione){e.printStackTrace();}try{conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","123456","abc");System.out.println("数据库连接成功");}catch(SQLExceptione){e.printStackTrace();}returnconn;}publicstaticvoidmain(String[]args){ConnmyConn=newConn();myConn.getConnection();}}如果各种配置正确,程序运行结果:
查看答案
搜索结果不匹配?点我反馈