mysql中的longtext字段在Java的po类中定义成啥类型?还有tinyint

mysql中的longtext字段在Java的po类中定义成啥类型?还有tinyint,第1张

因为long为长整型数据类型,所以mysql对应的是bigint或者numeric(x,y)也可以。

bigint:字节8个,当需要存储超大的整数才用。

numeric(x,y):其中x代表精度,y代表标度,精度表示保存值的主要位数,标度表示小数点后面可以保存的位数。你可以自定义你想要数据的大小。

我这有一篇别人的, 你先用用吧(未经过测试,但应该没问题)

// MySql2.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

//在DBMS中线要创建数据库www,table www,file字段数据类型用LONGTEXT即可测试

//测试文件c:\test.iso,你可以找任何一个文件修改为即可,我找的是一个exe程序,修改为test.iso而已

//最大测试过加入文件大小为650M(一个正真的iso文件)

//注意:还要修改my.ini文件中的max_allowed_packet字段,我设置的是

//max_allowed_packet = 1024M

//#define host "localhost" //mysql server

//#define username "root"

//#define password "674800"

//#define database "test"

//int port = 3306

#include <Winsock2.h>

#include <stdio.h>

#include <mysql.h>

#include <stdlib.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#define host "localhost" //mysql server

#define username "root"

#define password "674800"

#define database "www"

int port = 3306

#pragma comment(lib,"libmysql.lib")

//得到文件的大小(字节数)

int get_file_size(char *path, off_t *size)

{

struct stat file_stats

if(stat(path, &file_stats))

return -1

*size = file_stats.st_size

return 0

}

int main(int argc, char *argv[])

{

char *filename=NULL

off_t size

MYSQL *conn=NULL

MYSQL_RES *res_set=NULL

MYSQL_ROW row

MYSQL_FIELD *field=NULL

int i, flag

char *sql //sql语句

FILE *fp

char *buf

int n=256

char *end

unsigned long *length

/* if (argc != 2)

{

printf("Usage: %s srcfilen", argv[0])

exit(1)

}

*/

filename = "c:\test.iso"

if ((get_file_size(filename, &size)) == -1) //得到文件的大小

{

perror("get file size" )

exit(1)

}

if ((buf = (char *)malloc(sizeof(char)*(size+1))) == NULL)

{

perror("malloc buf" )

exit(1)

}

if ((fp = fopen(filename, "rb" )) == NULL) //读文件

{

perror("fopen file" )

exit(1)

}

if ((n = fread(buf, 1, size, fp)) <0) //读文件失败

{

perror("fread file" )

exit(1)

}

sql = (char *)malloc(sizeof(char)*n*2+256)//2n+1+strlen(other sql)

if (sql == NULL)

{

perror("malloc sql" )

exit(1)

}

conn = mysql_init(NULL)//生产一个mysql对象

if (conn == NULL)

{

printf("init mysql, %sn", mysql_error(conn))

exit(1)

}

if ((mysql_real_connect(conn, host, username, password, database, port, NULL, 0)) == NULL) //连接服务器

{

printf("connect mysql, %sn", mysql_error(conn))

exit(1)

}

strcpy(sql, "insert into www(id, name, file) values(NULL, 'peter', " )

end = sql

end += strlen(sql)//point sql tail

//convert NUL(ASCII 0)、'n'、'r'、''’、'''、'"'和Control-Z and so on

*end++ = '''

end += mysql_real_escape_string(conn, end, buf, n)

*end++ = '''

*end++ = ')'

flag = mysql_real_query(conn, sql, (unsigned int)(end-sql))

if (flag != 0)

{

printf("insert failed, %sn", mysql_error(conn))

exit(1)

}

if ((mysql_real_query(conn, "SELECT file FROM www where id=1", 31)) != 0)

{

printf("insert failed, %sn", mysql_error(conn))

exit(1)

}

res_set = mysql_store_result(conn)

fclose(fp)

fp = NULL

fp = fopen("c:\123.iso", "wb" )

while ((row = mysql_fetch_row(res_set)) != NULL)

{

length = mysql_fetch_lengths(res_set)

for (i=0i<mysql_num_fields(res_set)i++)

{

fwrite(row[0], 1, length[0], fp)

//printf("%sn",row[0])

}

}

fclose(fp)

mysql_close(conn)

free(sql)

free(buf)

sql = NULL

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9930566.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存