Skip to content

Commit

Permalink
localhost -> 127.0.0.1 某些机器没有在host里面设置127.0.0.1 localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
vagabond1-1983 committed Apr 2, 2016
1 parent b6c33b6 commit 143588a
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/test/basic/chapter8/DBDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class DBDemo {
public static void main(String[] args) {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String url = "jdbc:mysql://127.0.0.1:3306/test";
String username = "root";
String password = "password";

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/test/basic/chapter8/DBUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DBUtil {
//获取连接。饿汉式 推荐 。懒汉式就是在构造时连接上,然后方法返回connection。
public static Connection getConnection(String driver, String url, String username, String password) {
try {
if (null == conn && conn.isClosed()) {
if (null == conn || conn.isClosed()) {
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void main(String[] args) {
e.printStackTrace();
}
//创建数据连接对象
String url = "jdbc:mysql://localhost:3306/test";
String url = "jdbc:mysql://127.0.0.1:3306/test";
String username = "root";
String password = "password";
Connection connection = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/test/basic/chapter8/MySQLInsertDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class MySQLInsertDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8";
String url = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8";
String user = "root";
String password = "password";
String sql = "insert into users(username, password) VALUES(?, ?)";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/test/basic/chapter8/MySQLQueryDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class MySQLQueryDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
String url = "jdbc:mysql://localhost:3306/test";
String url = "jdbc:mysql://127.0.0.1:3306/test";
String user = "root";
String password = "password";
String sql = "select * from users";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/test/basic/chapter8/MySQLUpdateDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class MySQLUpdateDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
String url = "jdbc:mysql://localhost:3306/test";
String url = "jdbc:mysql://127.0.0.1:3306/test";
String user = "root";
String password = "password";
String sql = "update users set password = ? where username = ?";
Expand Down

0 comments on commit 143588a

Please sign in to comment.