采用java链接timesten内存数据库

来源:互联网 发布:手机淘宝2015旧版本 编辑:程序博客网 时间:2024/05/18 01:54
虽然主要是做TT的维保,但是由于TT使用的人相对少,很少相关的资料,就两java如何连接TT都很难找到,这里从官方文档中摘抄一段,做下记录备查。
##Write the below program in a file MyConnectionTest.java using vi or your favorite text editor.
#MyConnectionTest.java
import java.sql.*;

class MyConnectionTest {

  /* This is DSN that we specify in odbc.ini file */
  static String dsnname = "myjdbctest";

  /* URL to connect to the datastore, that contains the standard prefix and dsnname */
  static String url = "jdbc:timesten:direct:" + dsnname;

  public static void main (String args[])
  {
    /* Try to load the driver first */
    try {
    Class.forName("com.timesten.jdbc.TimesTenDriver");
    } catch (ClassNotFoundException ex) {
    System.out.println ("Failed to load the driver");
    ex.printStackTrace();
   }

   /* Try to get the connecction to TimesTen datastore and close it*/
   try {
   Connection con = DriverManager.getConnection(url);
   System.out.println ("Connection Success");
   con.close();
   } catch (SQLException ex) {
   System.out.println ("Failed to connect/disconnect to TimesTen datastore");
   ex.printStackTrace();
   }

}



编译:
javac MyConnectionTest.java
执行:
java MyConnectionTest

----------------------------End-------------------------------------------------
0 0
原创粉丝点击