I'm using the Azure table storage from java, following the tutorial here. I'm successfully able to create a table, add an entity, retrieve an entity and delete an entity. However, I've got this method to delete a table:
public void deleteTable(String tableName) {
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudTableClient tableClient = storageAccount.createCloudTableClient();
// Delete the table and all its data if it exists.
CloudTable cloudTable = new CloudTable(tableName, tableClient);
cloudTable.deleteIfExists();
} catch (Exception e) {
System.out.println("Error in deleting");
e.printStackTrace();
}
}
In this method I am getting an error on this line
CloudTable cloudTable = new CloudTable(tableName, tableClient);
which has no suggestions available within eclipse only the following markers:
Multiple markers at this line
The constructor CloudTable(String, CloudTableClient) is not visible
The constructor CloudTable(String, CloudTableClient) is not visible
Any help would be greatly appreciated.
If you look at CloudTable constructors here, you will notice that the code you're using is not a valid one. It is possible that the SDK got upgraded however the code sample isn't. I would suggest using getTableReference method on CloudTableClient to get an instance of CloudTable:
try
{
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount =
CloudStorageAccount.parse(storageConnectionString);
// Create the table client.
CloudTableClient tableClient = storageAccount.createCloudTableClient();
// Delete the table and all its data if it exists.
CloudTable cloudTable = tableClient.getTableReference("people");
cloudTable.deleteIfExists();
}
catch (Exception e)
{
// Output the stack trace.
e.printStackTrace();
}
Related
I am still searching around this subject, but I cannot find a simple solution, and I don't sure it doesn't exist.
Part 1
I have a service on my application that's generating an excel doc, by the dynamic DB data.
public static void
notiSubscribersToExcel(List<NotificationsSubscriber>
data) {
//generating the file dynamically from DB's data
String prefix = "./src/main/resources/static";
String directoryName = prefix + "/documents/";
String fileName = directoryName + "subscribers_list.xlsx";
File directory = new File(directoryName);
if (! directory.exists()){
directory.mkdir();
// If you require it to make the entire directory path including parents,
// use directory.mkdirs(); here instead.
}
try (OutputStream fileOut = new FileOutputStream(fileName)) {
wb.write(fileOut);
fileOut.close();
wb.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Part 2
I want to access it from the browser, so when I call it will get downloaded.
I know that for the static content, all I need to do is to call to the file, from the browser like that:
http://localhost:8080/documents/myfile.xlsx
After I would be able to do it, all I need is to create link to this url from my client app.
The problem -
Currently if I call to the file as above, it will download only the file which have been there in the compiling stage, but if I am generating a new files after the app is running the content won't be available.
It seems that the content is (as it's called) "static" and cannot be changed after startup.
So my question is
is there is a way to define a folder on the app structure that will be dynamic? I just want to access the new generated file.
BTW I found this answer and others which doing configuration methods, or web services, but I don't want all this. And I have tried some of them, but the result is the same.
FYI I don't bundle my client app with the server app, I run them from different hosts
The problem is to download the file with the dynamic content from a Spring app.
This can be solved with Spring BOOT. Here is the solution as shown in this illustration - when i click Download report, my app generates a dynamic Excel report and its downloaded to the browser:
From a JS, make a get request to a Spring Controller:
function DownloadReport(e){
//Post the values to the controller
window.location="../report" ;
}
Here is the Spring Controller GET Method with /report:
#RequestMapping(value = ["/report"], method = [RequestMethod.GET])
#ResponseBody
fun report(request: HttpServletRequest, response: HttpServletResponse) {
// Call exportExcel to generate an EXCEL doc with data using jxl.Workbook
val excelData = excel.exportExcel(myList)
try {
// Download the report.
val reportName = "ExcelReport.xls"
response.contentType = "application/vnd.ms-excel"
response.setHeader("Content-disposition", "attachment; filename=$reportName")
org.apache.commons.io.IOUtils.copy(excelData, response.outputStream)
response.flushBuffer()
} catch (e: Exception) {
e.printStackTrace()
}
}
This code is implemented in Kotlin - but you can implement it as easily in Java too.
I am developing an app to serve as a learning and I'm using Parse (parse.com) as a data source.
I am conducting download all objects of my classes in the parse and saving to a local store that has Parse. The following code snippet that performs one of downloads:
public void noticia_getOrUpdate(boolean isUpdate) throws ParseException {
ParseQuery<Noticia> query = new ParseQuery(Noticia.class);
query.orderByDescending("createdAt");
List<Noticia> lNoticias = null;
try {
if (isUpdate) {
lNoticias = query.whereGreaterThan("updatedAt", this.sPref.ultimaAtualizacao_noticia()).find();
if (!lNoticias.isEmpty())
ParseObject.pinAllInBackground(lNoticias);
} else {
query.whereEqualTo("ativo", true);
lNoticias = query.find();
for (Noticia noticia : lNoticias) {
if (noticia.getUpdatedAt().getTime() > this.sPref.ultimaAtualizacao_noticia().getTime())
this.sPref.atualiza_noticia(noticia.getUpdatedAt());
}
ParseObject.pinAllInBackground(lNoticias);
this.sPref.atualiza_isUpdate(true);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
The problem is I'm downloading all my classes, one is the File type, is a file that works as an image for my news ("Noticia"). I can download and store all on-site data storage, but can not recover using the following code:
public static byte[] NoticiaMidiaRelation(Noticia noticia) {
try {
ParseRelation<Midia> relation = noticia.getImagem();
Midia midia = relation.getQuery().fromLocalDatastore.whereEqualTo("ativo", true).getFirst();
if (midia != null && midia.getFileData() != null)
return midia.getFileData();
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
If retreat the "fromLocalDatastore" the query, he seeks the server and brings the file correctly, but do not want to pursue it again, because as said, already have the same image stored in the local data store.
Another way to do would be to get the relationship the media Id, after that perform a search for comparing ObjectId within the local store, but I think there's no way the property "parent". But if any, can be used as a solution.
You can't according to the documentation:
By default, when fetching an obj
ect, related ParseObjects are not fetched
There are work arounds but they might not be practical because by what I understand, you only have one image in your relation per ParseObject in your "Notica" class as you call getFirst(). In this case, using a Pointer would be a better decision but those aren't fetched by default either BUT they are cached to the LocalDatastore. You'll need to add the following code to your query to fetch the Pointer object.
query.include("your_column_key");
Im working with orient db where i have to export specified data tables using java. Here is the code im working with:
ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/sampleDB").open("admin", "admin");
try {
OCommandOutputListener listener = new OCommandOutputListener() {
#Override
public void onMessage(String iText) {
// System.out.print(iText);
}
};
Set<String> abcd = new HashSet<String>();
abcd.add("sample_demo1_OnlineShopping");
System.out.println(abcd);
ODatabaseExport export = new ODatabaseExport(db, "DataCont/Data.gz", listener);
export.setIncludeInfo(false);
export.setIncludeClusterDefinitions(false);
export.setIncludeSchema(false);
export.setIncludeIndexDefinitions(false);
export.setIncludeManualIndexes(false);
export.setIncludeClasses(abcd);
// export.exportRecords();
export.exportDatabase();
export.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
db.close();
}
The problem is, its not including any classes. Output file was like this:
{"records":[]}
But when i tries without the "setIncludeClasses" it prints all the classes available in the database. What would the issue for this problem. Thanks in advance.
Change this line to:
abcd.add("sample_demo1_OnlineShopping".toUpperCase());
I haven't found it in the documentation, but includeClasses is expecting classes in UpperCase (same for excludeClasses).
See the source code.
I wanted to upload a video on youtube using Java Google Data API. I got the following cod from the Google Data Api documentation to upload a video.The only thing i need to change in this code in Client ID and Porduct key. i am using followinf method to authenticate
YouTubeService service = new YouTubeService(clientID, developer_key);
Client key is my Google Email id , tried with with wasy,
only provided Username e,g. "sampleuser"
or complete Gmail id e.g. "sampleuser#gmail.com" or "smapleuser#googlemail.com"
i got developer key by logging my Google mail id as mentioned "smapleuser#googlemail.com"
but i always got following exception
com.google.gdata.util.AuthenticationException: Unauthorized
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.media.MediaService.insert(MediaService.java:400)
at YouTube.videoUpload(YouTube.java:115)
at YouTube.main(YouTube.java:43)
here is my code for video Upload
YouTubeService service = new YouTubeService("sampleuser#gmail.com",
"fakegoogleapplicationidjsuttoshowthatimgivingidhere");
// YouTubeService service = new YouTubeService("My Application");
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("My Test Movie");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("cars");
mg.getKeywords().addKeyword("funny");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("My description");
mg.setPrivate(false);
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
// alternatively, one could specify just a descriptive string
// newEntry.setLocation("Mountain View, CA");
MediaFileSource ms = new MediaFileSource(new File("D:\\maths.mp4")
, "video/quicktime");
newEntry.setMediaSource(ms);
// "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
String uploadUrl =
"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
try {
VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
please help , unable to find solution. thank you so much..looking for response
Try to add
service.setUserCredentials("email_here", "password_here");
i am trying to create an sample apps using GWT and my code is below
public void onModuleLoad() {
VerticalPanel panel = new VerticalPanel();
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
database data=new database();
Statement s1;
try {
s1 = data.conn.createStatement();
s1.executeQuery ("SELECT * FROM details LIMIT 10");
ResultSet rs = s1.getResultSet ();
while (rs.next ())
{
String name = rs.getString ("name");
oracle.add(name);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SuggestBox suggestbox = new SuggestBox(oracle);
panel.add(new Label("Enter Country"));
panel.add(suggestbox);
panel.addStyleName("demo-panel-padded");
RootPanel.get("demo").add(panel);
}
and i have added the mysql-bin.jar connector in war/WEB_INF/lib/ and now i am getting an compilation error
17:39:52.353 [ERROR] [a] Line 28: No source code is available for type java.sql.Statement; did you forget to inherit a required module?
i need to know why i am getting this error and how can i rectify it
You cannot use server-side code (java.sql.* in your case) in GWT client side modules.
You should make an RPC call to the server. The server callback should fetch the data from your database, and send it back to your GWT client.
Using Eclipse with the google plugin, you can create a new "Web Application Project". More information about the plugin can be found here: http://code.google.com/eclipse/
You will get a simple project that contains a GreetingService which receives a String from the client side and responds with "Hello" + string. For your example you would have to add the code that reads from the DB in the GreetingServiceImpl class and then use the response (which can be a String[] containing the name read from DB) on the client side to populate the SuggestionBox