有只小跳蛙
12345678910111213141516String driverName = "com.mysql.jdbc.Driver"; // 加载JDBC驱动String dbURL = "jdbc:mysql://localhost:3306/test"; // 连接服务器和数据库testString userName = "sa"; // 默认用户名String userPwd = "sa"; // 密码java.sql.Connection dbConn; try { Class.forName(driverName).newInstance(); dbConn = java.sql.DriverManager.getConnection(dbURL, userName, userPwd); System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!} catch (ClassNotFoundException e) { System.out.println("没有找到驱动");} catch (Exception e) { // TODO: handle exception e.printStackTrace();}