I need to copy often the lasts rows of a single table in MSSQL to MySQL table.
I've created a java script and all works but I think that it's possible improve the performance.
I've replicate the table schema and import data with MySQL ODBC 5.1 Driver connector adding it in MSSQL and using Openquery.
It's possible use it directly on java?
What is this the best way to handle this task?
Thanks in advance.
Luca
MySQL Workbench has a utility to do this.
In the program, connect to your MySQL Database, and then choose Database -> Migrate.
~Christian
Related
I create database using Workbench
Export database.mwb to database.sql
Import database.sql in PHPMyAdmin
Connect with Java
Question: is the 3rd step necessary?
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "root", "pass");
It appears that what you've described is a rather roundabout way of initially setting up your database.
You're creating a database structure in MySQL Workbench, then exporting it as an SQL file, then importing it through phpMyAdmin in order to create the database structure. What you can instead do is create the structure directly through MySQL Workbench (or phpMyAdmin; both can do it), which will skip the steps of needing to export and reimport the SQL. Rather than using the two tools, each for a small part of your workflow, you could use one tool for both parts of the process and eliminate a lot of the extra steps.
Note that this assumes you've got the proper access; if your phpMyAdmin is on a hosted environment where you can't connect from MySQL Workbench, then you obviously won't be able to connect from Workbench to create the structure, in which case you can create it from phpMyAdmin directly on your hosted server.
But ultimately, you're only doing this when you first create the application, right? You shouldn't need to recreate your database structure....well, more than once, ideally, though if you upgrade your schema due to changing your application, then I suppose you'd do it more than once, but still not very often.
Anyway, the only reason you'd have to continue to follow this workflow is if you force yourself to use Workbench and can't get Workbench to connect to your remote MySQL server. Otherwise, there are more efficient ways to connect.
It seems that I was just a beginner :p
I've never created the data base, I've just created the schema.
Thank you!
I have MySQL installed, but It takes more than 1 GB of C drive. However the database file is only some KB's. I want to help to transfer the database file into single file that is in the Java program data folder. Also i want to know how to change the connection to be that file instead of using JDBC?
Thank you.
So a fast edit after long time ago 😂
that day i meant that I want to use something like SQLite instead of MySQL
I think that clarifies it now
waiting for new answers.
First of all, you questions is structured in a way that i do not fully understand it. However let me make things clear.
In order for java program to connect to Database you need a driver ( typically JDBC ). The database HAS to be on some sort of "server" i.e apache, sql server, derby etc. If you want to save some HDD space i suggest looking into Derby Database, which is "integrated" database
EDIT:
Or you can just host external database on some hosting server ;), there are some free ones out there too !
You might want an embedded database, like h2 or java Derby.
Such an embedded database often is stored as file, without external database engine runnin (it might do that too though). The API remains JDBC.
What I needed was mySQLite, it's saved on the device as a single file and easily managed through java.
What you need to do is to export the mysql database
And use dbmigration app to convert it to sqlite then use your database as you wish
I am creating a web application that is accessing a SQLite database in the server. I also have "clients" that updates this same database. As we know SQLite locks the entire database during INSERTs which are done by the clients and the web application is also trying to make some UPDATEs at the same time. So my problem now is about concurrency in database access. I would like to use an embeddable database like SQLite. Any suggestions.
H2 database the new thing from the creator of Hypersonic SQL: H2 stands for Hypersonic 2, however H2 does not share code with Hypersonic SQL or HSQLDB. H2 is built from scratch.
HSQLDB
If you value convenience over raw performance the database bundled with Java 6, JavaDB/Derby, may work well for you. It offers row-level locking and has it enabled by default.
You've got to the point where I would be switching to using a separate database server. The SQLite wiki has a page on when to use SQLite and when not; highly concurrent writes are one of the times when you're beyond its architecture (which deliberately doesn't handle this case well so it can do better at others).
PostgreSQL and MySQL are probably your first ports of call.
Try Oracle's Berkeley DB.
Thought about MySQL? We're using it in our application an it works great.
I got a new project from my teacher to convert database to another. How can I convert a MS SQL database into MySQL using Java?
You will want to keep in mind that there are two logical steps regardless of the Programming environment. Firstly, you will want to map the schema of the database to an equivalent schema in the target database. This means mapping data types and constraints. Sometimes there are cases where it is simply not possible. Secondly, mapping the data from one database to the other. Timestamps and date formats must be equivalent for example. Hope that helps you to get started.
How can I convert a MS SQL database into MYSQL using JAVA
Dump it ( from MSSQL) and execute the result in Mysql.
With a question like that it's the best answer you can give
You could also try to use the hibernate tools to create a mapping to the MS SQL tables. Then use hibernate again with the created mapping to create the tables in MySQL.
Look at the various metadata classes in JDBC:
java.sql.DatabaseMetaData
java.sql.ResultSetMetaData
These will allow you to get the structure from the MSSQL DB. You need to do a little experimentation as, if memory serves, what gets returned in the metadata can vary from database to database.
Once you've worked out how to get the metadata from the MSSQL DB you need to convert that into SQL commands to recreate the structure in the MySQL DB.
Then with the structure in place you can start copying the data between the two by creating insert queries that run against the MySQL DB from querying the contents of the MSSQL DB. You'll need to do this in the correct order so that the referential integrity isn't violated which again you'll be able to determine from the metadata.
It's an interesting academic exercise but in the real-world you'd use an Extract-Transform-Load (ETL) tool.
I am doing a database migration work. I have to copy a database in MSSQL to MySql database. It was possible to come up with a small java utility to copy table stucture from MSSQL to MySql Database. Now i have to copy all data from MSSQL to MySql. I tried using resultset in java to obtain all data from a table but then it could only fetch a small part of data. Is there any alternate solution to get all data from table to resultset or to some other similar structure which i could possibly use, to insert the same data into mysql Db. There are more than 25,00,000 records for a table.
A JDBC result set should in principle allow you to iterate the entirity of a large query result.
However going via Java may not be the most efficient approach. Bulk export to a file and bulk import may be the way to go. It appears that MS has a bcp utility that may do the export.
The best way to achieve a database migration like you describe is to use and ETL Tool - there's a good overview of ETL here:
http://en.wikipedia.org/wiki/Extract,_transform,_load
There's no reason why you wouldn't be able to do this with JDBC and so if you are set on rolling your own please elaborate on 'could only fetch a small part of data':
what is the query you are running?
are you getting an exception?
which JDBC driver are you using to connect to MS-SQL?