The first way depends on the JDBC module in the pom:
<dependency> <groupId>org.apache.linkis</groupId> <artifactId>linkis-jdbc-driver</artifactId> <version>${linkis.version}</version> </dependency>
Note: The module has not been deployed to the central repository. You need to execute mvn install -Dmaven.test.skip=true in the linkis-computation-governance/linkis-jdbc-driver directory for local installation.
The second way is through packaging and compilation:
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.Establish a Java test class LinkisJDBCTest, the specific interface meaning can be seen in the notes:
package org.apache.linkis.jdbc.test; import java.sql.*; public class LinkisJDBCTest { public static void main(String[] args) throws SQLException, ClassNotFoundException { //1. load driver:org.apache.linkis.ujes.jdbc.UJESSQLDriver Class.forName("org.apache.linkis.ujes.jdbc.UJESSQLDriver"); //2. Get Connection:jdbc:linkis://gatewayIP:gatewayPort/dbName?EngineType=hive&creator=test, user/password Connection connection = DriverManager.getConnection("jdbc:linkis://127.0.0.1:9001/default?EngineType=hive&creator=test","hadoop","hadoop"); //3. Create statement Statement st= connection.createStatement(); ResultSet rs=st.executeQuery("show tables"); //4.get result while (rs.next()) { ResultSetMetaData metaData = rs.getMetaData(); for (int i = 1; i <= metaData.getColumnCount(); i++) { System.out.print(metaData.getColumnName(i) + ":" +metaData.getColumnTypeName(i)+": "+ rs.getObject(i) + " "); } System.out.println(); } //close resource rs.close(); st.close(); connection.close(); } }