Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
@Mod(
modid = "sqlmod",
name = "SQLMod",
version = "1.0"
)
public class SQLMod {
@Instance("sqlmod")
public static SQLMod instance;
@SubscribeEvent
public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
SqlConnect.Connect();
}
}
public class SqlConnect {
private final static String createTableQuery = "CREATE TABLE `test` (" +
" `number` double default NULL," +
" `test` varchar(50) default NULL," +
" PRIMARY KEY (`id`)" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
public static void Connect() {
Connection connection = null;
Statement statement = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/test" +
"?characterEncoding=utf8";
connection = DriverManager.getConnection(url, "test", "root");
statement = connection.createStatement();
statement.executeUpdate(createTableQuery);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
String request = "SELECT ... WHERE USERNAME = '" + someString + "'";