⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testoracletime.cpp

📁 testOracleConnect.rar is a sample about Oracle Connection.
💻 CPP
字号:
// testOracleTime.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "testOracleTime.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
	//	CString strHello;
	//	strHello.LoadString(IDS_HELLO);
	//	cout << (LPCTSTR)strHello << endl;
		CTestTime m;
		m.TestTime();
	}

	return nRetCode;
}
bool CTestTime::TestTime()
{
	CoInitialize(0);
	HRESULT hr;
	try
	{
		hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
		if(SUCCEEDED(hr))
		{
			//	_bstr_t DSN="Driver={Oracle in Oracle};Server=10.80.2.141;UID=110;PWD=110;";
			//	_bstr_t DSN="Driver={SQLServer};Server=10.80.2.132;UID=sa;PWD=123456;";
			//	_bstr_t DSN="Provider=SQLOLEDB; data source=10.80.2.132;initial catalog=FaxInf; user id=sa; password=123456;"; //sqlserver is good
//			_bstr_t DSN="provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\cei50\\test.mdb;UID=admin,PWD=test";
		
			_bstr_t DSN="provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb";
			//	_bstr_t DSN="MyWire";
//			_bstr_t UID="dlhy";
//			_bstr_t PWD="dlhy";
//			hr = m_pConnection->Open(DSN,"admin","test",adModeShareDenyNone);///连接数据库
			
			//Access 添加密码
//				_bstr_t DSN="provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb;Jet OLEDB:DataBase Password=test";
			hr = m_pConnection->Open(DSN,"","",adModeUnknown);///连接数据库
			_bstr_t bSql="insert into test values('2','2','2','2')";
			m_pConnection->Execute(bSql,NULL,0);
			 //hr = m_pConnection->Open(DSN,"","",adModeUnknown);///连接数据库
			///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51; }
			int t=20;
			_variant_t index0=(short)0;
			_variant_t index1=(short)2;
			CString strSql="select * from test where 1=1";
			BSTR bstrSQL = strSql.AllocSysString();
			_RecordsetPtr m_pRecordset;
			m_pRecordset.CreateInstance("ADODB.Recordset");
			m_pRecordset->Open(bstrSQL,(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
			//	m_pRecordset1->Open(bstrSQL1,(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
			SYSTEMTIME systime;
			GetSystemTime(&systime);
			char str[50];
			wsprintf(str, "%u/%u/%u  %u:%u:%u:%u", 
				systime.wYear, systime.wMonth, systime.wDay,
				systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds);
			
			while(!m_pRecordset->adoEOF )
			{
			//	_bstr_t TheValue1=m_pRecordset->Fields->GetItem("name")->Value;
				SYSTEMTIME s;
			VARIANT sfsf=m_pRecordset->Fields->GetItem("school")->Value ;
			double decConversionFactor;
   			decConversionFactor = 86400000.0;
			double decTime;
			decTime = sfsf.date;
//			decTime = fabs(decTime);				
			decTime = decTime - int(decTime);
			decTime = (decTime * decConversionFactor);
			int  millisecond = int(decTime+0.5)%1000;
			VariantTimeToSystemTime(sfsf.date,&s);
			//	_bstr_t TheValue2=m_pRecordset->Fields->GetItem("timestart")->Value ;
			//	CString temp=TheValue2.copy(); //获得文件名
			//	if(temp!="0")
			//		AfxMessageBox(temp);
				m_pRecordset->MoveNext();//转到下一条纪录	
			}
			m_pRecordset->Close ();//结束
		}
	}
	catch(_com_error e)///捕捉异常
	{
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);///显示错误信息
		return false;
	} 	
//	if(m_pConnection->State)
//		m_pConnection->Close();
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -