publicclassMySqlJDBSUtil { privatestaticStringdriver="com.mysql.jdbc.Driver"; privatestaticStringurl="jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8"; privatestaticStringuserName="root"; // base on your login user name privatestaticStringpassword="!qaz2wsx"; // base on your login user
System.out.println("Record is inserted into USER_INFO table Success!");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (preparedStatement != null) { preparedStatement.close(); }
if (dbConnection != null) { dbConnection.close(); }
} } }
二,测试
运行结果:
INSERT INTO USER_INFO (USER_ID, USERNAME, CREATED_BY,CREATED_DATE) VALUES (1,'devnp.com','system','2017-03-29')
Record is inserted into USER_INFO table Success!
INSERT INTO USER_INFO (USER_ID, USERNAME, CREATED_BY,CREATED_DATE) VALUES (2,'devnp.com','system','2017-03-29')
Record is inserted into USER_INFO table Success!