怎么读取mysql中数字 mysql读取sqlserver数据( 二 )


//一次性取得数据集
result = mysql_store_result(mydata);
//取得并打印行数
int rowcount = mysql_num_rows(result);
cout"row count: "rowcountendl;
//取得并打印各字段的名称
unsigned int fieldcount = mysql_num_fields(result);
MYSQL_FIELD *field = NULL;
for (unsigned int i = 0; ifieldcount; i++) {
field = mysql_fetch_field_direct(result, i);
coutfield-name"\t\t";
}
coutendl;
//打印各行
MYSQL_ROW row = NULL;
row = mysql_fetch_row(result);
while (NULL != row) {
for (int i = 0; ifieldcount; i++) {
coutrow[i]"\t\t";
}
coutendl;
row = mysql_fetch_row(result);
}
} else {
cout"mysql_query() select data failed"endl;
mysql_close(mydata);
return -1;
}
#ifdef STEPBYSTEP
system("pause");
#endif
//删除刚才建的表
sqlstr = "DROP TABLE user_info";
if (0 == mysql_query(mydata, sqlstr.c_str())) {
cout"mysql_query() drop table succeed"endl;
} else {
cout"mysql_query() drop table failed"endl;
mysql_close(mydata);
return -1;
}
mysql_free_result(result);
mysql_close(mydata);
mysql_server_end();
system("pause");
return 0;
}
怎样从mysql数据库中读取数据 , 并保存到数组?给你写了段代码.主读取在get_data函数中.
?php
define("HOST","localhost");
define("DB","demo");
define("DBUSER","root");
define("DBPASSWD", "mysql");
$local_conn = mysql_connect(HOST,DBUSER,DBPASSWD);
if(!isset($local_conn)) exit();
mysql_select_db(DB);
$sql = "set names utf8";
mysql_query($sql,$local_conn);
function get_data($conn,$name){
$sql = "select * from t_demo where timelike'".$name."'";
$resultRows = @mysql_query($sql,$conn);
while($trow = @mysql_fetch_array($resultRows)){
$result[] = $trow;
}
mysql_free_result($resultRows);
return $result;
}
$result = get_data($local_conn,"test");
?
如何读取mysql数据库所有数据大概的基本流程如下: 连接数据库,再加一个判断 。选择数据库 读取表 输出表中数据 下面是代码: 如果你的switch是表头,就定义这个表头字段,然后输出 。
怎么获取到mysql表格里面的数据怎么获取到mysql表格里面的数据
可以通过查询系统表来获取 。
1、打开Navicat for Mysql,登录到指定数据库下 。
2、新建查询 。
3、输入以下语句:
1
select column_name from information_schema.COLUMNS where table_name='表名'
java中怎么获取mysql数据库的数据用JDBC连接数据库,然后用sql语句 。要导入mysql的驱动包 。
import java.sql.*;
public class TestMySql {
static Connection con = null; // 声明Connection对象
static Statement sql = null;
static ResultSet res = null;
public static void main(String[] args) {
TestMySql c = new TestMySql();
con = c.getConnection();
try {
sql = con.createStatement();
res = sql.executeQuery("select * from dept");
//sql语句,我数据库里有张dept表
while (res.next()) {//输出结果
System.out.print(res.getString(1) + "——");
System.out.print(res.getString(2) + "——");
System.out.print(res.getString(3) );
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (res != null) {
res.close();
res =null;
}
if (sql != null) {
sql.close();
sql =null;
}
if (con != null) {
con.close();
con =null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public Connection getConnection() {
try {

推荐阅读