我已经寻找了很久,但我似乎找不到在我的spigot插件可执行文件中有一个数据库的方法,所以如果有人能帮助我,那就太棒了。
首选数据库: SQLite MySQL
发布于 2021-08-29 10:54:18
您不能在插件可执行文件中包含(运行)数据库。数据库在服务器上运行,您可以建立到它的连接。所有SQL内容都在java.sql包中。
你可以在你的电脑上运行一个数据库,就像你本地的“我的世界”服务器,抛出XAMPP。
下面是一个如何建立到本地运行数据库的连接的示例:
Connection connection;
String host, port, username, password, databaseName;
host = "localhost"; // enter your host (ip address)
port = "3306"; // the entering port
username = "root"; // your username
password = ""; // your password
databaseName = "database-name"; // the database name, where you want to connect to
String url = "jdbc:mysql://" + host + ":" + port + "/" + databaseName;
try {
connection = DriverManager.getConnection(url, username, password);
} catch (SQLException throwables) {
throwables.printStackTrace();
}我建议您创建一个SQL类,在其中管理所有内容。Maby在Youtube上寻找如何在Java中使用SQL的教程。
https://stackoverflow.com/questions/68847979
复制相似问题