I am developing a small app for hotels. I am using java and mysql. I use mysql to save booking information and guest data and so on.
But now I want to make my program to be more flexible.
For example if I want to add more apartments(store apartment names) or change the payment methods. At this time I store the data as binary in files and read them from there when I start the program or when I need them.
Is this method correct? or is a better way? Should I use the mysql and read the data from there?
You should use a mySQL database. Store the data in tables with different columns based on the info. Use the tables to store the information so you don't need to convert it to binary.
To talk to the table, use the JDBC. There is a nice tutoral on using JDBC with mySQL. Refer to the SQL website on setting up tables on your mySQL database.
Related
There is a lot of tutorials out there showing me how to create a new table and ammend the data. But will creating a new table every time overwrite my existing table?
Once the table has been created and the rows of data have been added, I wouldn't need my program to create a new table again. Just read and ammend from it.
I don't want the user to create a table, so I just want the table to already be there before I even run my program.
I figured I could use run something like this to create my database tables once:
https://www.tutorialspoint.com/jdbc/jdbc-create-database.htm
Run it! And then once it is created, use this next guide to connect to where I stored it in the actual program.
https://www.tutorialspoint.com/jdbc/jdbc-select-database.htm
Be nice to find a tutorial on how to just manually make the database parameters outside of code.
The project is for university, they want me to create a client similar to MySpace. Have clients connect to a server, share music and message friends. I have done the UI and multi threaded server connections and understand how to read and write data to the UI or File. Just figured an SQL database would be the best way to store all this user data.
You just need to check the table Exist or not.
If the table exist then use it else create it and then you can use it.
We have an application that runs with any of IBM Informix, MySQL and Oracle, and we are using Java with Hibernate to connect to the database. We will store XML, CSV and other text-based files inside the database (clob column). The entities in Java are byte[] objects.
One feature request to the application is now to "grep" content inside the data. So I need to find all files with a specific content.
On regular char/varchar fields I can use like '%xyz%', but this is not working on byte[] / blobs.
The first approach was to load each entity, cast the byte[] into a string and use the contains method in Java. If the use enters any filter parameters on other (non-clob) columns, I will apply those filters before testing the clob in order to reduce the number of blobs I have to scan.
That worked quite well for 100 files (clobs) and as long as the application and database are on the same server. But I think it will get really slow if I have 1.000.000 files inside the database and the database is not always in the same network. So I think that is not a good idea.
My next thought was creating a database procedure. But I am not quite sure if this is possible for Informix, MySQL and Oracle. And I am not sure if this is possible.
The last but not favored method is to store the content of the data not inside a clob. Maybe I can use a different datatype for that?
Does anyone has a good idea how to realize that? I need a solution for all three DBMS. The application knows on what kind of DBMS it is connected to. So it would be okay, if I have three different solutions (one for each DBMS).
I am completely open to changing what kind of datatype I use (BLOB, CLOB ...) — I can modify that as I want.
Note: the clobs will range from about 5 KiB to about 500 KiB, with a maximum of 1 MiB.
Look into Apache Lucene or other text indexing library.
https://en.wikipedia.org/wiki/Lucene
http://en.wikipedia.org/wiki/Full_text_search
If you go with a DB specific solution like Oracle Text Search you will have to implement a custom solution for each database. I know from experience that Oracle Text search takes significant time to learn and involves a lot of tweaking to get just right.
Also, if you use a DB solution you would receive different results in each DB even if the data sets were the same (each DB would have it's own methods of indexing and retrieving the data).
By going with a 3rd party solution like Lucene -- you only have to learn one solution and results will be consistent regardless of the Db.
I am new to jbpm and would like to know if the already configured H2 db stores the objects(DataItems) associated with the process and work item in it somewhere.
I can see there is a byte array present in both the tables and I am not sure what exactly that bytearray stores and how to unmarshall it.
Any sort of information would be really helpful.
Thanks.
The *Info objects do store all relevant data the engine needs in a binary format. This is not meant for query purposes however. If you want to get access to variable values, either use the audit logs or use pluggable variable persistence to store them separately (for example by making them a JPA entity they will be stored in a separate table).
I tried to make this as simple as possible with a short example.
We have two databases, one in MSSQLServer and other in Progress.
We have the user DTO as it follows that we shown in a UI table within a web application.
User
int, id
String, name
String, accountNumber
String, street
String, city
String, country
Now this DTO(Entity) is not stored only in one database, some information (fields) for the same user are stored in one database and some in the other database.
MSsql
Table user
int, id
String, name
String, accountNumber
Table userModel
int, id
String, street
String, city
String, country
As you can see the key is the only piece that link two tables in both databases, as I said before they are not in the same database and not using same database vendor.
We have a requirement for sorting the UI table for each column. Obviously we need to create user dto with the information coming from both databases.
Our proposal at this moment is if user want to apply sorting using street field, we run a query in the Progress database and obtain a page (using pagination) using this resultset and go directly to the MSSQLServer User table with those keys and run another query to extract the missing information and save it to our DTO and transfer it to the UI. With implies run a query in one database then other query based on the returned keys in the second database.
The order of the database could change depending in which column(field) the user wants to apply sorting.
Technically we will create a jparepository that acts as a facade and depending on the field make the process in the correct database.
My question is:
There is some kind of pattern that is commonly used in this scenarios, we are using spring, so probably spring have some out of the box features to support this requirement, will be great if this is possible using jparepositories (I have several doubts about it as we will use two different entitymanagers, one for each database).
Note: Move data from one database to another is not an option.
For this, you need to have separate DataSource/EntityManagerFactory/JpaRepository.
There is no out-of-the-box support for this architecture in the Spring framework, but you can easily hide the dual DataSource pair behind a Service layer. You can even configure JTA DataSources for ACID operations.
As you will always need to fetch data from both databases, why not populate local java User objects then sort these objects (using a comparator with the appropriate fields you want to sort on).
The advantage of sorting locally vs doing the sort in the database query is that you won't have to send requests to the database every time you change the sorting field.
So, to summarize:
1- Issue two sql queries for the two databases to get your users
2- Build your User objects using the retrieved values
3- Use Java comparators to sort the users on any field without having to issue new queries to the database.
My advice would be to find a way to link 2 databases together so that you can utilize database driver features without your code being affected.
Essentially if Progress database can be linked to SQL Server, you will be able to query both databases using a single SQL query with a join on id column and you will get a merged, sorted and paginated result set for your application to display.
I am not an expert in Progress database but it seems there is an ODBC driver for it so you might try to link it to SQL Server.
My requirement is I want to diff two database which can be any database ,for now considering 3 database Oracle,MySQL,PostGresql and suppose if any of two database has a common schema with common table name,but lets say those two tables are different. The tables can have different column or different column data type etc.How can I generate a diff query which on can be executed on a particular DB to make both of them equal. I was going through schemacrawler(http://schemacrawler.sourceforge.net/how-to.html) but didint got any API which can be used to generated DDL. Though the tool is good to crawl through schema and table -columns etc,but how can I generate DDL in java so that I can make both database equal. I can get database meta data using java api but how can I use it to generate appropriate DDL to make both database equal,if possible please paste sample code snippet.
We use tool called DBSolo to compare schema and generate diff sql. It is invoked via scripts, not using java code though.
I used liquibase in my personal work. The example given are in script, it will be trivial to integrate using java.