我的数据库存在问题。它是您可以使用Netbeans创建的数据库。我想插入一个长度超过255个字符的字符串。我看到你可以说varchar(512)
。但是我在我的班级中使用@Entity
- 注释和属性生成我的表格。
如何将更长的字符串放入数据库?
我正在使用Netbeans 8.0.2。
答案 0 :(得分:2)
在您的实体类中,对所需字段使用columnDefinition="VARCHAR(512)"
注释,并指定- (NSArray *)postPhoto:(NSData *)jpegData withRoomType:(NSString *)roomType andDescription:(NSString *)description {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0);
__block NSArray *returnedMetaData;
AFHTTPRequestOperation *operation = [self.requestManager POST:[Constants postPhotoURLString] parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSLog(@"Room: %@", roomType);
[formData appendPartWithFormData:[roomType dataUsingEncoding:NSUTF8StringEncoding]
name:@"room"];
NSLog(@"Description: %@", description);
[formData appendPartWithFormData:[description dataUsingEncoding:NSUTF8StringEncoding]
name:@"description"];
[formData appendPartWithFileData:jpegData
name:@"image"
fileName:@"photo.jpg"
mimeType:@"image/jpeg"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
returnedMetaData = (NSArray *)responseObject;
dispatch_semaphore_signal(semaphore);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", error.description);
dispatch_semaphore_signal(semaphore);
}];
operation.completionQueue = queue;
[operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten,
long long totalBytesWritten,
long long totalBytesExpectedToWrite) {
NSLog(@"Wrote %lld/%lld", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation start];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return returnedMetaData;
}
。