In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
The aggregator provides a JDBC driver that can be easily embedded in Java program calls in a way similar to executing SQL and stored procedures in Java.
Deploy aggregator JDBC in Java application
First, deploy JDBC to the java application project, simply putting the jar package and configuration file needed to load the aggregator when you start the JAVA application into the project. It is important to note that the JDK version required by the aggregator JDBC must not be less than 1.6.
1. Load driver jar
The aggregator JDBC is similar to a database JDBC driver without physical tables, which can be simply regarded as a database with only stored procedures. In addition, the aggregator JDBC is a completely embedded computing engine, which has completed all the operations in JDBC. Unlike the database, JDBC is just an interface, and the actual operation is done in an independent database server.
If you are in the web application project, you can put these jar packages in the WEB-INF/lib directory. The aggregator JDBC requires three basic jar packages, all of which can be found in the [installation directory]\ esProc\ lib directory:
Dm.jar / / aggregator calculation engine and JDBC driver package
Icu4j_3_4_5.jar / / dealing with internationalization
Jdom.jar / / parsing configuration file
In addition to the required jar above, there are some jar packages for specific functions:
For example, if the database is used as a data source, then the driver jar package of the corresponding database is also required.
To read and write Office files, you need to add poi*.jar and xmlbeans.jar
To use the drawing function, you need to add jar packages related to SVG graphics processing, including batik*.jar, js.jar, pdf-transcoder.jar, xalan-2.6.0.jar, xercesImpl.jar, xml-apis.jar, xml-apis-ext.jar.
two。 Deploy raqsoftConfig.xml
The aggregator also has an important configuration file raqsoftConfig.xml, which can be found in the [installation directory]\ esProc\ config. It needs to be copied and placed under the classpath of the application project. The name of the configuration file cannot be changed.
In the raqsoftConfig.xml file, all kinds of information such as authorization information, main path of aggregator, dfx file addressing path and so on are configured. Let's first take a look at the most basic configuration, that is, the aggregate authorization file configuration:
< Config Version="2">Esproc.xml
Java call
Calling SPL script in Java program is similar to calling SQL and stored procedure in java. Let's take a look at how to implement it:
Execute SPL statement
For example, create a data table, add two fields baseNum and square2, insert the natural numbers and their square values into the data table, and finally return the data in the table as a result set.
The Java code is as follows:
Public void runSPL () throws ClassNotFoundException, SQLException {
Connection con = null
PreparedStatement st
ResultSet set
/ / establish a connection
Class._forName_ ("com.esproc.jdbc.InternalDriver")
Con= DriverManager._getConnection_ ("jdbc:esproc:local://")
/ / execute the SPL statement directly and return the result set
St = (PreparedStatement) con.createStatement ()
ResultSet rs = st.executeQuery ("= 100.new (~: baseNum,~*~:square2)")
/ / simply process the result set and output the field names and data in the result set
ResultSetMetaData rsmd = rs.getMetaData ()
Int colCount = rsmd.getColumnCount ()
For (int c = 1; c 1) {
System._out_.print ("\ t")
}
Else {
System._out_.print ("\ n")
}
System._out_.print (title)
}
While (rs.next ()) {
For (int c = 1; c 1) {
System._out_.print ("\ t")
}
Else {
System._out_.print ("\ n")
}
Object o = rs.getObject (c)
System._out_.print (o_.toString ())
}
}
/ / close the connection
If (contextual null) {
Con.close ()
}
Execution result:
Access local files in SPL
You can also access local files through SPL, including Txt, Excel, Json, Csv, Ctx and other files. When accessing, you can check the file location by absolute path or relative path. When using relative path, it is relative to the home directory in the configuration file, so let's configure the home directory first:
In the node of the raqsoftConfig.xml file
< Esproc >Add the following nodes in:
D:\ mainFile
We put the file employee.txt to be called under the home directory. When calling in JAVA, the code for establishing the connection and outputting the result is exactly the same as the above example. The part of calling SPL statement is as follows:
ResultSet rs=st.executeQuery ("= file (\" D:\ mainFile\ employee.txt\ ") .import@t ()")
The use of absolute and relative paths is supported here, and the backslash\ is used in Java to indicate the escape character.
Execution result:
For this simple operation, you can also use a simple SQL syntax:
ResultSet rs=st.executeQuery ("$() select * from employee.txt")
Where $() indicates access to the local file system, and the result set of the two methods is the same.
SPL statement with parameters
Parameters are an important part of the SQL statement. Similarly, the use of parameters is also supported in the SPL statement. For example, as in the above example, you want to query the data in the employee.txt file, but you are required to query only records with salaries between 12000 and 20000, and sort them according to the ascending order of wages:
The calling code is as follows:
PreparedStatement pst = con.prepareStatement ("$() select * from employee.txt where SALARY >? and SALARY
< ? order by SALARY"); //设置参数 pst.setObject(1,12000); pst.setObject(2,20000); ResultSet rs = pst.executeQuery(); 其中用?表示参数,然后通过 setObject() 为上面的参数一一赋值。 执行结果: 有数据源的 SPL 语句 集算器 JDBC 既然是个数据计算引擎,那么数据来源的重要途径之一就是数据库了,JAVA 中如何来调用带数据源的 SPL 语句呢?往下看: JAVA 调用带数据源的 SPL 语句之前,需要先在应用项目中添加对应的数据库驱动,然后在配置文件 raqsoftConfig.xml 中配置数据源信息。 例如:调用的 SPL 语句中使用的数据源名称为 demo,数据库类型为 HSQL,那么配置如下: 首先,将 HSQL 的数据集驱动 hsqldb.jar 加载到应用项目中; 其次,在 raqsoftConfig.Xml 的 < Runtime >Configure data source information in the node:
Now we query the SALES table from the demo data source through SPL and filter out all order information for employees with SELLERID 3 for the period from November 11, 2014 to December 12, 2014:
The calling code is as follows:
PreparedStatement pst = con.prepareStatement ("$(demo) select * from SALES where SELLERID =? and ORDERDATE >? and ORDERDATE
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.