Task Submission And Execution Of JDBC API Documents

1. Introduce Dependent Modules

The first way depends on the JDBC module in the pom:

  1. <dependency>
  2. <groupId>org.apache.linkis</groupId>
  3. <artifactId>linkis-ujes-jdbc</artifactId>
  4. <version>${linkis.version}</version>
  5. </dependency>

Note: The module has not been deployed to the central repository. You need to execute mvn install -Dmaven.test.skip=true in the ujes/jdbc directory for local installation.

The second way is through packaging and compilation:

  1. Enter the ujes/jdbc directory in the Linkis project and enter the command in the terminal to package mvn assembly:assembly -Dmaven.test.skip=true The packaging instruction skips the running of the unit test and the compilation of the test code, and packages the dependencies required by the JDBC module into the Jar package.
  2. After the packaging is complete, two Jar packages will be generated in the target directory of JDBC. The one with dependencies in the Jar package name is the Jar package we need.

2. Create A Test Category

Establish a Java test class LinkisClientImplTestJ, the specific interface meaning can be seen in the notes:

  1. public static void main(String[] args) throws SQLException, ClassNotFoundException {
  2. //1. Load driver class:org.apache.linkis.ujes.jdbc.UJESSQLDriver
  3. Class.forName("org.apache.linkis.ujes.jdbc.UJESSQLDriver");
  4. //2. Get connection:jdbc:linkis://gatewayIP:gatewayPort
  5. // the front-end account password
  6. Connection connection = DriverManager.getConnection("jdbc:linkis://127.0.0.1:9001","username","password");
  7. //3. Create statement and execute query
  8. Statement st= connection.createStatement();
  9. ResultSet rs=st.executeQuery("show tables");
  10. //4. Processing the returned results of the database (using the ResultSet class)
  11. while (rs.next()) {
  12. ResultSetMetaData metaData = rs.getMetaData();
  13. for (int i = 1; i <= metaData.getColumnCount(); i++) {
  14. System.out.print(metaData.getColumnName(i) + ":" +metaData.getColumnTypeName(i)+": "+ rs.getObject(i) + " ");
  15. }
  16. System.out.println();
  17. }
  18. // close resourse
  19. rs.close();
  20. st.close();
  21. connection.close();
  22. }