| Installation | Types | Basic Operations | Prepared Statements | Stored Procedures | Database information |
Basic JDBC-like Operations supported.
ACDK SQL classes are quite similar to the JDBC (Java Database Connection) standard.
// This Statement is currently needed to load the ODBC-DLL.
// If no Class from acdk::sql::odbc is used, Class::forName will fail!
// So let's start with a dummy line ...
RDriver tdriver = (RDriver)Class::forName("acdk::sql::odbc::ODBCDriver")->newInstance();
RString url = "jdbc:odbc:acdk/user=acdk/password=acdk";
RDriver driver = DriverManager::getDriver(url);
if (driver == Nil)
testAssertComment(false, "Cannot load driver: " + url);
// get a connection
RConnection connection = driver->connect(url, Nil);
|
// create a statment from the connection
RStatement statement = connection->createStatement();
RString sql = "SELECT intcol, realcol, stringcol FROM acdk_select_test";
RResultSet rset = statement->executeQuery(sql);
while (rset->next() == true)
{
// read a column via position (starts with 1, not 0)
int intcol = rset->getInt(1);
// read a column via name
float floatcol = rset->getFloat("realcol");
RString sval = rset->getString("stringcol");
}
}
|
{
// insert some data into the table
for (int i = 0; i < 2; i++)
{
float f = i + 0.5;
RString sql = SBSTR("INSERT INTO acdk_select_test VALUES ( " << i << ", " << f << ", " << "'stm: " << i << "')"
);
RStatement statement = connection->createStatement();
int rows = statement->executeUpdate(sql);
}
}
|
// create a table
RString sql = "CREATE TABLE acdk_select_test ( intcol int, realcol real, stringcol Varchar(100) )";
RStatement statement = connection->createStatement();
statement->executeUpdate(sql);
|
{
// delete a table, if it already exists
RStatement statement;
try {
RString sql = "DROP TABLE acdk_select_test";
RStatement statement = connection->createStatement();
int rows = statement->executeUpdate(sql);
} catch (RSQLException ex) {
}
|
If the ODBC driver is no longer needed you can call:
DriverManager::deregisterDriver(tdriver);
|
|