esenbase的使用练习

jdbc 练习

  • 亿信华晨常用的jar包都集成在esenbase中啦 直接在 Nexus搜索下载

eclipse maven项目构建

  • eclipsej2ee 内置maven 说下配置pom.xml 实现如下功能
  • 优先在nexus下载jar 没有再从外网找 同式复制一份到nexus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
......
<repositories>
<repository>
<id>esenSnapshots</id>
<name>esenSnapshots</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://cc:8081/nexus/content/groups/public</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>esenSnapshots</id>
<name>esenSnapshots</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://cc:8081/nexus/content/groups/public</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</project>


练习完整源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.fangjun.esensoft2;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import com.esen.*;
import com.esen.edf.domain.Result;
import com.esen.jdbc.ConnectionFactory;
import com.esen.jdbc.SimpleConnectionFactory;
import com.esen.jdbc.dialect.DataBaseInfo;
import com.esen.jdbc.dialect.DbDefiner;
import com.esen.jdbc.dialect.Dialect;
import com.essbase.services.olap.grid.Connection;
import com.essbase.services.olap.maxl.Statement;
import com.ibm.db2.jcc.a.db;
import com.informix.util.dateUtil;
import com.informix.util.stringUtil;
import com.mysql.jdbc.PreparedStatement;
import com.sanlink.util.FileFunc;
import com.sanlink.util.StmFunc;
import com.sanlink.util.StrFunc;
import com.sanlink.util.StringMap;
import com.sanlink.util.XmlFunc;

import aj.org.objectweb.asm.Type;


/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/test";
String user="root";
String pwd="admin";

SimpleConnectionFactory fct=new SimpleConnectionFactory(driver,url,user,pwd, "debug");
//获取数据库信息
DataBaseInfo dbinfo=fct.getDialect().getDataBaseInfo();
System.out.println("daNmae="+dbinfo.getDbName());
System.out.println("Schema="+dbinfo.getDefaultSchema());
System.out.println("Version="+dbinfo.getDriverVersion()+dbinfo.getDatabaseMajorVersion()+dbinfo.getDatabaseMinorVersion());

//创建表
testCreatTable(fct);

//插入
testInsert(fct);

//查询
testSelect(fct);

//方言
testDialect(fct);

try {
fct.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
static void testCreatTable(SimpleConnectionFactory fct) {
DbDefiner dbf=fct.getDbDefiner();
String tableName="TestJdbcTable";

//定义字段
dbf.defineAutoIncField("ID_", 1);
dbf.defineStringField("NAME_", 20, "'default name'", false, false);
dbf.defineDateField("CreateDate_", null, true, false);
dbf.defineBlobField("photo_", null, true, false);
dbf.defineClobField("resume_", null, true, false);

dbf.defineField("introduction_",DbDefiner.FIELD_TYPE_STR,100,0,null,true,false);

//定义主键
dbf.definePrimaryKey("ID_");

//定义索引
dbf.defineIndex(null, "NAME_", false);

//创建表
java.sql.Connection conn;
try {
conn=fct.getConnection();
try {
//删除后重建
dbf.dropTable(conn, null, tableName);
dbf.createTable(conn, null, tableName);
//直接创建自动更名
dbf.createTable(conn, tableName,false);
} catch (Exception e) {
// TODO: handle exception
}finally {
fct.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}

static void testInsert(ConnectionFactory fct) {
String tableName="TestJdbcTable";
try {
java.sql.Connection conn=fct.getConnection();
try {
String sql="insert into"+tableName
+"(name_,createdate_,introduction_,photo_,resume_)values(?,?,?,?,?)";
java.sql.PreparedStatement pstmt=conn.prepareStatement(sql);
try {
pstmt.setString(1, "zhangsan");
pstmt.setDate(2, Date.valueOf("2018-10-30"));
pstmt.setString(3, "introduction_intoduction_introduction");
pstmt.setNull(4, Types.BLOB);
pstmt.setNull(5, Types.CHAR);
pstmt.addBatch();

pstmt.setString(1, "lisi");
pstmt.setDate(2, Date.valueOf("2017-10-30"));
pstmt.setString(3, "introduction_李四intoduction_introduction");
pstmt.setNull(4, Types.BLOB);
pstmt.setNull(5, Types.CHAR);
pstmt.addBatch();

pstmt.executeBatch();


} catch (Exception e) {
// TODO: handle exception
}finally {
pstmt.close();
}
} catch (Exception e) {
// TODO: handle exception
}finally {
conn.close();
}
} catch (Exception e) {
// TODO: handle exception
}
}

static void testSelect(ConnectionFactory fct) {
System.out.println("\n test select");

String tableName="TestJdbcTable";
try {
java.sql.Connection conn=fct.getConnection();
try {
String sql="select id_,name_,createdate_,introduction_ from"+tableName;
java.sql.Statement stmt=conn.createStatement();
try {
ResultSet rs=stmt.executeQuery(sql);

try {
while (rs.next()) {
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)
+"\t"+rs.getString(3)+"\t"+rs.getString(4)+"\t"+rs.getString(5));


}
} finally {
// TODO: handle finally clause
rs.close();
}
} finally {
// TODO: handle finally clause
stmt.close();
}
} finally {
// TODO: handle finally clause
conn.close();
}
} catch (Exception e) {
// TODO: handle exceptioe.
e.printStackTrace();

}
}

static void testDialect(ConnectionFactory fct) {
System.out.println("\n test Dialect" );
Dialect dl=fct.getDialect();
String tableName="TestJdbcTable";

try {
java.sql.Connection conn=fct.getConnection();
try {
String sql="select id_,"
+dl.funcNow()
+",name_,"+dl.funcLen("name_")
+","+dl.funcRepeat("name_", "3")
+"from"+tableName;
java.sql.Statement stmt=conn.createStatement();
try {
ResultSet rs=stmt.executeQuery(sql);
try {
while (rs.next()) {
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)
+"\t"+rs.getString(3)+"\t"+rs.getString(4)+"\t"+rs.getString(5));

}
} finally {
// w: handle finally clause
rs.close();
}

System.out.println("\n countsql:");
System.out.println(dl.getCountString(sql));
System.out.println("\n createTablesql:");
System.out.println(dl.getCreateTableByQureySql("newTableNmae", sql, false));
} finally {
// TODO: handle finally clause
stmt.close();
}

} finally {
// TODO: handle finally clause
conn.close();
}
} catch (Exception e) {
// TODO: handle exception
}
}


}