String url = "jdbc:jtds:sqlserver://localhost:1433/mydatabase"; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT * FROM employees"); while (resultSet.next()) { } Statement statement = connection.createStatement(); int rowsAffected = statement.executeUpdate("INSERT INTO employees (name, age) VALUES ('John Doe', 25)"); if (resultSet != null) resultSet.close(); if (statement != null) statement.close(); if (connection != null) connection.close();


上一篇:
下一篇:
切换中文