步骤 4:连接到您的数据库
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
让我们在包含生成类的项目中编写一个普通的 main 类
// For convenience, always static import your generated tables and jOOQ functions to decrease verbosity: import static test.generated.Tables.*; import static org.jooq.impl.DSL.*; import java.sql.*; public class Main { public static void main(String[] args) { String userName = "root"; String password = ""; String url = "jdbc:mysql://:3306/library"; // Connection is the only JDBC resource that we need // PreparedStatement and ResultSet are handled by jOOQ, internally try (Connection conn = DriverManager.getConnection(url, userName, password)) { // ... } // For the sake of this tutorial, let's keep exception handling simple catch (Exception e) { e.printStackTrace(); } } }
这是建立 MySQL 连接的相当标准的代码。
反馈
您对此页面有任何反馈吗? 我们很乐意听到!