1. 在使用ODBC连接数据库时,为什么要在控制面板/管理工具/ODBC数据源中进行设置?所起的作用是什么?这个步骤在使用ODBC连接时是不是必须的?麻烦能比较详细的讲下,谢谢这个解释起来比较多,建议你可以先在GOOGLE中搜索一下ODBC / ADO 等相关的介绍。 2. 在C++程序(控制台程序)中,是怎样实现连接的,打开,操作,关闭等等是如何实现? 这个你可以直接在MYSQL的C API文档中找到例子。 ======================================================================= Application programs should use this general outline for interacting with MySQL: Initialize the MySQL library by calling mysql_library_init(). This function exists in both the mysqlclient C client library and the mysqld embedded server library, so it is used whether you build a regular client program by linking with the -libmysqlclient flag, or an embedded server application by linking with the -libmysqld flag. Initialize a connection handler by calling mysql_init() and connect to the server by calling mysql_real_connect(). Issue SQL statements and process their results. (The following discussion provides more information about how to do this.) Close the connection to the MySQL server by calling mysql_close(). End use of the MySQL library by calling mysql_library_end(). While a connection is active, the client may send SQL statements to the server using mysql_query() or mysql_real_query(). The difference between the two is that mysql_query() expects the query to be specified as a null-terminated string whereas mysql_real_query() expects a counted string. If the string contains binary data (which may include null bytes), you must use mysql_real_query(). For each non-SELECT query (for example, INSERT, UPDATE, DELETE), you can find out how many rows were changed (affected) by calling mysql_affected_rows(). In both cases, you access rows by calling mysql_fetch_row(). With mysql_store_result(), mysql_fetch_row() accesses rows that have previously been fetched from the server. With mysql_use_result(), mysql_fetch_row() actually retrieves the row from the server. Information about the size of the data in each row is available by calling mysql_fetch_lengths(). After you are done with a result set, call mysql_free_result() to free the memory used for it. MYSQL_ROW row; unsigned int num_fields; unsigned int i;num_fields = mysql_num_fields(result); while ((row = mysql_fetch_row(result))) { unsigned long *lengths; lengths = mysql_fetch_lengths(result); for(i = 0; i < num_fields; i++) { printf("[%.*s] ", (int) lengths[i], row[i] ? row[i] : "NULL"); } printf("\n"); } MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
其次熟悉你要使用的语言
最后自己动手做一下,不懂的问题再问
String user = "test";
String password = "test";
String driver = "com.mysql.jdbc.Driver";
String uri = "jdbc:mysql://10.10.1.102:3306/db_tigerstone?useUnicode=true&characterEncoding=UTF8";
try {
Class.forName(driver);
conn = DriverManager.getConnection(uri, user, password);
return conn;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
1. 在使用ODBC连接数据库时,为什么要在控制面板/管理工具/ODBC数据源中进行设置?所起的作用是什么?这个步骤在使用ODBC连接时是不是必须的?麻烦能比较详细的讲下,谢谢
2. 在C++程序(控制台程序)中,是怎样实现连接的,打开,操作,关闭等等是如何实现?
2. 在C++程序(控制台程序)中,是怎样实现连接的,打开,操作,关闭等等是如何实现?
这个你可以直接在MYSQL的C API文档中找到例子。
=======================================================================
Application programs should use this general outline for interacting with MySQL: Initialize the MySQL library by calling mysql_library_init(). This function exists in both the mysqlclient C client library and the mysqld embedded server library, so it is used whether you build a regular client program by linking with the -libmysqlclient flag, or an embedded server application by linking with the -libmysqld flag. Initialize a connection handler by calling mysql_init() and connect to the server by calling mysql_real_connect(). Issue SQL statements and process their results. (The following discussion provides more information about how to do this.) Close the connection to the MySQL server by calling mysql_close(). End use of the MySQL library by calling mysql_library_end().
While a connection is active, the client may send SQL statements to the server using mysql_query() or mysql_real_query(). The difference between the two is that mysql_query() expects the query to be specified as a null-terminated string whereas mysql_real_query() expects a counted string. If the string contains binary data (which may include null bytes), you must use mysql_real_query(). For each non-SELECT query (for example, INSERT, UPDATE, DELETE), you can find out how many rows were changed (affected) by calling mysql_affected_rows().
In both cases, you access rows by calling mysql_fetch_row(). With mysql_store_result(), mysql_fetch_row() accesses rows that have previously been fetched from the server. With mysql_use_result(), mysql_fetch_row() actually retrieves the row from the server. Information about the size of the data in each row is available by calling mysql_fetch_lengths(). After you are done with a result set, call mysql_free_result() to free the memory used for it.
MYSQL_ROW row;
unsigned int num_fields;
unsigned int i;num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
{
printf("[%.*s] ", (int) lengths[i],
row[i] ? row[i] : "NULL");
}
printf("\n");
}
MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
vicozo (冰露花语)
'截至2010-08-23 14:58:38 用户结帖率60.53%当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖