WWW.LOUGH.COM.CN

加入收藏 | 设为首页 | 联系站长
首页 | Java | C&C++ | 数据库 | 经验交流
论坛首页 | 综合区 | 贴图区 | 狐朋狗友 | 学习区 | 站务区
博客首页 | IT技术 | WebServices | Hibernate | Java设计模式 | Struts | AJAX | 数据库
首页 | 中华古籍 | 网络原创 | 随记

Java中通过ADO连接数据库

Java中通过ADO连接数据库

实现方法如下: 
{
Connection c = new Connection();
c.setConnectionString ("dsn=aDSNName;pwd=aName;pwd=aPWD;database=aDatabase");
c.setCommandTimeout (10);
c.setConnectionTimeout (10);
c.setCursorLocation (AdoEnums.adUseClientBatch);



c.open();
c.setDefaultDatabase ("aSpecificDatabase");
System.out.println ("Connection string = " + c.getConnectionString());



// Verify that the propertiea on the connection 
// were set correctly. If not, return a fail condition.
if (c.getCommandTimeout() != 10)
return false;



if (c.getConnectionTimeout() != 10)
return false;



if (c.getCursorLocation() != AdoEnums.adUseClientBatch)
return false;



if (c.getMode() != AdoEnums.adModeUnknown)
return false;



// Create a new Recordset to contain the results 
// of the SQL DML operation (select * ...). 
Recordset rs= c.execute ("select * from authors");
rs.moveFirst();
rs.moveLast();



// Delete all rows from the authors table. 
c.executeUpdate ("delete from authors");



// Close the Connection and Recordset. 
rs.close();
c.close();
return true; 
}    
 

关于我们 | 站点地图 | 免责声明 | 联系我们 | ©2003-2007 Lough.com.cn 京ICP备06060948号