今天研究了一下PointBase,感觉是还是很好的,对平台的依赖性很小,而且特别的小,我是仅仅的用了3个jar 包 和一个bat 文件就完美的搞定了一个数据库,搭建仅仅需要3分钟。
搭建过程:
在任何地方找到pbclient44.jar,pbserver44.jar,pbtools44.jar
大家也看到了,为什么我不选用其他版本的jar 包。仅仅选用了4.4版本
那是因为IBM太坏了,5.0以上版本就加了限制,也就是说多了licence,这个不是免费的,也就用不了了。
4.4 版本的就很好,没有这样的限制而且很稳定,下面就开始吧。
@rem ************************************************************************* @rem This script is used to start PointBase @rem ************************************************************************* @echo off set POINTBASE_HOME=.. set POINTBASE_CLASSPATH=%POINTBASE_HOME%\lib\pbserver44.jar;%POINTBASE_HOME%\lib\pbclient44.jar @rem Add PointBase classes to the classpath set CLASSPATH=%POINTBASE_CLASSPATH% @rem Start PointBase "%JAVA_HOME%\bin\java" com.pointbase.net.netServer /port:9092 /d:3 /pointbase.ini=".\pointbase.ini"
database.home=../databases documentation.home=../ transaction.isolationlevel=TRANSACTION_READ_COMMITTED database.pagesize=4096 cache.size=2063 sort.size=1024
好了基本想研究的,我想bat还是能看懂的。
下面这来说明一下JDBC的书写:
package com.pointbase; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; /** * * @author cnchenhl Apr 12, 2011 */ public class JDBC { public static void main(String[] args) { try { String str = executeSelectSQL("select count(*) from people"); System.out.println(str); } catch (Exception e) { e.printStackTrace();package com.pointbase; /** * @author cnchenhl Apr 13, 2011 */ public final class CommonConstants { public static String USERNAME = null; public static String PASSWORD = null; public static String DBURL = null; public static String FILENAME = "database.properties"; }} } public static Connection getConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, FileNotFoundException, IOException, SQLException { Class.forName("com.pointbase.jdbc.jdbcUniversalDriver").newInstance(); Properties properties = Configuration.getProperties(CommonConstants.FILENAME); CommonConstants.USERNAME = properties.getProperty("userName"); CommonConstants.PASSWORD = properties.getProperty("password"); CommonConstants.DBURL = properties.getProperty("url"); Connection conn = DriverManager.getConnection(CommonConstants.DBURL, CommonConstants.USERNAME, CommonConstants.PASSWORD); return conn; } public static Statement getStatement() throws FileNotFoundException, InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, SQLException { Connection conn = getConnection(); Statement stat = conn.createStatement(); return stat; } public static String executeSelectSQL(String sql) throws FileNotFoundException, InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, SQLException { Statement stat = getStatement(); ResultSet rs = stat.executeQuery(sql); String str = ""; while(rs.next()){ str = rs.getString(1); } return str; } }
package com.pointbase; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; /** * * @author cnchenhl * Apr 13, 2011 */ public class Configuration { public static Properties getProperties(String fileName) throws FileNotFoundException, IOException{ Properties pro = new Properties(); File propertyFile = new File(fileName); pro.load(new BufferedInputStream(new FileInputStream(propertyFile))); return pro; } }
#User Name userName = ××××× #Password password = ××××× #URL of Database url = jdbc:pointbase:server://localhost/sample
好了 大功告成,Pointbase 搭建成功了
只要书写JDBC 就能改变PointBase数据库了
很简单,很强大哦