我已经学习 java 大约 3 周了。我想用java连接mysql,我现在正在尝试。但有一个问题。我已经为我的 ubuntu 安装了 php、apache、mysql 三个。我可以从port 80
. 我认为连接数据库时出现问题,这就是我说端口的原因。
这是我的桌子:
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(2) | NO | PRI | NULL | auto_increment |
| name | varchar(32) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
这是java代码:
import java.sql.DriverManager;
import java.sql.Statement;
public class Main {
public static void main(String args[]) {
try {
java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:80/test", "root", "1");
Statement state = (Statement) conn.createStatement();
String name = "try";
state.executeUpdate("INSERT INTO deneme (name) VALUES (" + name + ")");
} catch (Exception e) {
}
}
}
此代码运行大约 20 秒并返回BUILD SUCCESSFUL (total time: 21 seconds)
What is your idea about this question?