esenbase的使用练习 Posted on 2018-10-30 | In 亿信华晨 | jdbc 练习 亿信华晨常用的jar包都集成在esenbase中啦 直接在 Nexus搜索下载 eclipse maven项目构建 eclipsej2ee 内置maven 说下配置pom.xml 实现如下功能 优先在nexus下载jar 没有再从外网找 同式复制一份到nexus 1234567891011121314151617181920212223242526272829303132333435363738......<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> 练习完整源码123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234package 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 } }}