採用java連結timesten記憶體資料庫

tangyunoracle發表於2013-12-26
雖然主要是做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-------------------------------------------------

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24930246/viewspace-1064596/,如需轉載,請註明出處,否則將追究法律責任。

相關文章