导入jar包并加入工程 mysql-connector-java-5.1.7-bin.jar
创建四个字符串
private static String driverClass = null;
private static String jdbcUrl = null;
private static String user = null;
private static String pwd = null;
用Properties来动态的为四个字符串初始化
File file = new File("./src/properties.properties");
InputStream inputStream = new FileInputStream(file);
properties = new Properties();
properties.load(inputStream);
driverClass = properties.getProperty("driverclass");
jdbcUrl = properties.getProperty("jdbcurl");
user = properties.getProperty("user");
pwd = properties.getProperty("pwd");
加载驱动 和 创建连接
Class.forName(driverClass);
connection = DriverManager.getConnection(jdbcUrl,user,pwd);
调用connection的prepareStatement