I have a situation like this.
Some of my data was compressed using gzdeflate() function in php and stored in the database. Now I need to do some work with the data stored in database. I tried a lot of options in Java(including GZipStream, Inflater etc) but was unable to retrieve the data from database.
So I thought of using gzinflate() function in php and was able to retrieve the data quite easily. Now I have the data in a variable in php which I want to pass back to my java program so that I can continue with my previous work.
I have come across some of the options like Java/PHP bridge, Caurces and all but couldn't find a way either.
Is there a way which can solve this requirement of mine. I am stuck in this part for a while now and would really appreciate your help.
Try JZlib library to decompress using java. JZlib can inflate data deflated by zlib.
Related
I'm starting to work on a new Java desktop app that should help me and my colleagues learn vocabulary. It will contain around 700 words, some texts (that point to the words contained in them) and maybe some images (not sure about that part yet). The data will never change and I want the program to be able to run offline.
The question is: Should I use database, text file or serialize the data into file? Or perhaps if there is any other option I don't know about? If you could explain your choice in detail I would be glad.
If the data never changes and is only 700 words it would probably be easiest to use a file.
If your data was a bit more complex and had many fields and was being constantly updated, a database would be more preferable but a csv file could still be used.
Since you want to access this data offline and data never changes, I think the best option would be to just use text file, which will be more efficient in terms of access and speed.
Keep all the data in memory as Serializable Java objects, and store them serialized when your application is not running. Evaluate airomem - really nice solution that would perfectly work for you.
I need to get data from table id="maintable" from website "http://trackinn.az/GeoLoc/reports.aspx?login=ho&password=ho". I tried many methods some of them worked for other websites but not for this one. Could someone help pls?
Thanks.
You cannot get data from that table. It is being dynamically created by javascript (AJAX particularly). And I don't think there is any api wich can process javascript.
It would be possible to get data if it was a static file or the part you want would be static, but it is not.
If you are using this site to get geolocation, then use google geocoding api for this. it would be better option.
I have an application which stores information in a JList. However, of course, when the application is closed all of the information is deleted from memory.
I'm trying to build the app so that when re-launched, it will contain the same data. So is there a way to store this data in a database or similar and if so? Where and how do I go about this?
The simplest way to persist IMHO is in a File.
Try using Properties if you need a key-value map.
Or, if it you're binding more complex objects I recommend a Simple XML serialization package.
You need to connect your application to a database using JDBC. JDBC stands for Java Database Connectivity. As you can see from the name, it lets you to connect to a database. Hence, you can link your application to a database,and store your data persistenly.Here's a link to start off with. And here is something for further reading.
If the data is not complex and is not large (more than a few instances of a few objects) you could persist the list to a file using serialization. This will get you started. If you list is large or complex you might consider a database. Searching for JDBC will in your favorite search engine will get you started.
I think you want a plain flat file. It's simple; you can have one going in no time. (The learning curve is much less than with databases.) And it's fast; you can read a 1 GB file before you can even log on to a DB. Java serialization is a bit tricky, but it can be a very powerful way to save vast amounts of complicated data. (See here for things to watch out for, plus more helpful links.) If, for instance, you wanted to save a large, complex game between sessions, serializing it is the way to go. No need to convert an Object Oriented structure to a relational one.
Use a database:
if you want to add data to a large file, or read only part of the data from a large file. Or if other processes are going to read and modify it.
Consider a DB:
if you are already using one for other purposes. If the user might start on another machine and have trouble finding the file from the last session and the data is not too extensive. Or if the data is relational in nature anyway and someone else may be interested in looking at it.
So if you have a simple case where the user always starts in the same directory, just write and read a simple file. If you have a lot of complex, extensive OO data, use a flat file even if it is not easy to do--you'll need the speed. Otherwise, think about a DB.
So I want to do the simplest possible thing.
Assume I have a MYSQL enabled hosting service.
In it, I have a database storyland and a table story-->(id, title, text)
I only know how to write Java programs in eclipse that run on my computer and do homework assignments well...:)
Now I want to
1) write a Java program that is hosted on my server that would compute and return (for example) the number of characters of text stored in the entire MYSQL database
Then I also only have experience with writing PHP programs that talk directly to MYSQL via forms e.t.c but now i want to
2) be able to display a page index.php that says
echo "Welcome to storyland, there are $textcount
characters of text in all stories here";
where $textcount is the number returned by the java service.
I would appreciate really specific answers for this really "simple" specific example..to get me started. I'd also appreciate answers/resources that do not lean too heavily on external libraries/software since i want to be able to understand how those libraries work to be able to decide how to use them in future.
Thanks!
A design thought: I'd be tempted to have one more column - size, and have that precomputed for each blob of text, so you wouldn't have to calculate that (which might be expensive to count a blob > varchar size). Then I'd just issue a SUM over that column and be done: SELECT SUM(size) from mytable;
That would make the db work real simple, a simple INSERT and SELECT system really.
You need to have your own server, or a server that supports java, else this is not possible.
Even if you have a server that supports java, why do this with java when you can do it with php, the bottleneck will probably be the database anyhow.
I'm working on an application with a javascript front end that can receive a bunch of octets from the server (for the time being I'm using php's chr() to simulate some data).
Trying to pass the data from javascript into an applet to be manipulated is proving difficult. Since the data can have nulls mid-string, it looks like it gets terminated at the first null going in. It also looks like once the binary data touches a javascript variable the encoding messes with some of the bytes (or maybe that's just a problem with how I'm displaying it)
Either way, what options do I have for taking a block of binary data, sent from a server and putting it into a Java applet to be manipulated. Is a conversion to base64 (or some other encoding) my only option if I want to maintain data integrity?
All this is new to me, so hopefully I got things across clearly.
Ah the bane of liveconnect.
Yes, you either need or use urlencode or base64 to get your data through.
Even when passing stuff from JavaScript to Flash (or back) you need to this, because the interface in between uses null terminated strings (which is just stupid, I know).
I think that architecture when your java script gets binary data and passes it to java applet is not optimal. Did you probably think to modify applet to make it to go directly to server and get the binary data? Without any java script?