`
Intrepid2012
  • 浏览: 70865 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Timesten 学习笔记(六)Java

 
阅读更多

连接timesten 数据库,在Java下有两种方法:

 

第一种,使用 Drivermanager

 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class TTTest {

	public static void main(String[] args) {
      // create the TimesTen data source and set the connection URL
    	String URL = "jdbc:timesten:direct:dsn=my_ttdb;UID=oracle;PWD=oracle";
		Connection conn = null;

		try {
		     Class.forName("com.timesten.jdbc.TimesTenDriver");
		} catch (ClassNotFoundException ex) {
		      // See "Handling errors"
		}

		try {
		    // Open a connection to TimesTen
		    conn = DriverManager.getConnection(URL);
		    System.out.println("success");
 
      // create and execute the statement
      Statement stmt = conn.createStatement();
      ResultSet rset = stmt.executeQuery("select count(*) from cmn_tn2lrn201");
 
      // process the result set
      while(rset.next()) {
        System.out.println("Value: " + rset.getInt(1));
      }
    } catch(SQLException e) {
      e.printStackTrace();
    }
}
	}

 

 

第二种 使用Datasource

 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class TTTest {

	public static void main(String[] args) {
       
        TimesTenDataSource ds = new TimesTenDataSource();
         ds.setUser(myttusername);                    // User name to log in to TimesTen.
         ds.setPassword(myttpwd);                     // Password to log in to TimesTen.
         ds.setUrl("jdbc:timesten:direct:<dsn>");
         ds.setOraclePassword(myorapwd);              // Password to log in to Oracle.
         Connection conn = ds.getConnection();

 
      // create and execute the statement
      Statement stmt = conn.createStatement();
      ResultSet rset = stmt.executeQuery("select count(*) from cmn_tn2lrn201");
 
      // process the result set
      while(rset.next()) {
        System.out.println("Value: " + rset.getInt(1));
      }
    } catch(SQLException e) {
      e.printStackTrace();
    }
}
	}
 
分享到:
评论
1 楼 qqkou 2013-11-11  
不用加ip地址吗?最近在学习timesten,一直找不到连接方法啊,求帮助。

相关推荐

Global site tag (gtag.js) - Google Analytics