MySQL Dump File is Excluding almost all Insert Statements - java

I created a DB using MySQL, the script to create this database creates 4 tables and has multiple inserts satetments for each table.
After I run the script the tables are created and the insert statements run without an error.
I run a Java app that also uses the DB and the app runs perfectly and I can see that the insert statements have been added.
However when I create a dump file via the Windows CMD line the sql file that is generated by the CMD Command only contains one insert statement for
each table. Why does this happen ?

It's possible to use a bulk insert that inserts all rows from one table in one statement (multiple value lists will appear after the insert statement). Depending on how large your tables are, or how many indexes and foreign keys you have, this can be very efficient when dumping and restoring.
I expect that the windows cmd line is invoking this option (--extended-insert or -e) by default, whereas whatever you used to create the initial dump was using single row inserts.
Can you check the output from the windows cmd line dump carefully, or perhaps paste an excerpt from it here?
Alternatively if you just run
mysqldump your-database-name > your-dumpfile-name.sql
(ie: no flags or options)
Then you should get multiple insert statements.

Related

H2 database with corrupted table

We have an H2 database with what looks to be a corrupted table. Using the H2 web console, we are able to run SELECT * queries on all the tables except one. For this one table, TBL_TRANSACTION, we get the error result:
SELECT * FROM TBL_TRANSACTION;
General error: "java.nio.BufferUnderflowException"; SQL statement:
SELECT * FROM TBL_TRANSACTION [50000-190] HY000/50000
When we run the H2 Recover tool, we get the following:
java -cp h2-1.4.190.jar org.h2.tools.Recover
Error: java.nio.BufferUnderflowException
The Recover tool does generate the h2.sql and the mv.txt file. However, after all the CREATE and INSERT statements, the h2.sql ends with
// error: java.nio.BufferUnderflowException
Running RunScript against this h2.sql file does recover a part of the corrupted table, but only a very small part (only up to the part where the BufferUnderFlowException occurred.)
Questions:
What could have happened to cause this corruption?
What steps can we take to recover the data?
Thanks in advance.

Is it possible to use JDBC to update multiple columns with a single string separated by " \t " or " \ " [duplicate]

I just was wodering if there's an equivalent to MySQL LOAD DATA INFILE statemnent in Oracle? I need it because I want to read from a huge textfile into a database table.
Oracle gives the SQLLoader commandline utility. But it relies on a proper formatting of the data file.
You can try to look at Oracle External Tables (e.g. you can link a csv file as an external table and see it as a table within Oracle).
Both solutions have pros and cons, but the big cons is that they still rely on data input format (so if you have a file ready for mysql, you may need to tweak it a bit).
Example on windows 10 and Oracle 12c
if you have a text file with records of each table delimited by comma, you can do this:
Create a control file for each table, called table_name.ctl (C:\Users\user\Desktop\directory\table_name.ctl)
load data
infile 'C:\Users\user\Desktop\directory\table_name.txt'
append
into table table_name
fields terminated by ","
(id, field2,field3)
After, In windows you should open Cmd and load data in each table, and then load data remotely for example in a aws server.
sqlldr userid=USER#AWS_PDB1/password
control='C:\Users\user\Desktop\directory\table_name.ctl' log='C:\Users\user\Desktop\directory\table_name.log' direct=true
or
sqlldr control='C:\Users\user\Desktop\directory\table_name.ctl' log='C:\Users\user\Desktop\directory\table_name.log' direct=true
and then ask them the user and password
If you have the following error:“The program can’t start because oranfsodm12.dll is missing from your computer. Try reinstalling the program to fix this problem.”
it is because SQL * Loader
is disabled and can not be used in the console windows, this is solved
enabling the following steps (as http://www.dallasmarks.com/installing-two-oracle-12c-clients-on-one-server/):
Should go to the folder
C:\oracle\client\user\product\12.1.0\client_1\BIN
Make a copy of oraodm12.dll file, calling the new file
oranfsodm12.dll, and paste it in the same BIN folder.
Run the command again from cmd.

How do I back up a MySQL database

I have created a Web Application using Java JSP and for a Database I used MySql server 5.5. I am running on windows and the application works just fine. My question is, where is the actual physical database stored, i can not find it anywhere on my computer, and the reason why i am asking is portability, if i copy and paste and run the project on different machine, there is a problem connecting to the database, i can recreate the schema of the database, but the actual data stored in the database i can not find it.
Please help
Use mysqldump to backup your database:
The mysqldump client is a backup program originally written by Igor
Romanenko. It can be used to dump a database or a collection of
databases for backup or transfer to another SQL server (not
necessarily a MySQL server). The dump typically contains SQL
statements to create the table, populate it, or both. However,
mysqldump can also be used to generate files in CSV, other delimited
text, or XML format.
An alternative option if you don't want to use the commandline is to use a program like HeidiSQL

how to get new records from MySQL using java

I am working with Java and MySQL. I wrote code in Java. I have 10000 rows and 5 columns(id,name,address,contactNo and status) in MySQL table.
I wrote code for updating the contactNo in table.
I have created the jar for my class and it is working fine. Jar is working properly on the command prompt.
Here I am running the query as follows:
select id,name,address,status from student where status = 0 limit 0,50
after getting records updated, I am setting the status=1,so it will execute continuously.
I am updating the 10,000 records, so when I try to run jar on two command prompt, here I am getting the issue:
records which are getting updated on first command prompt, the same records are getting updated on second command prompt, but I don't want the same records to be updated on second command prompt.
How do I get the new records updated on the second command prompt?
It's difficult to give you code to help solve your problem when you haven't provided any, but I can tell you that your stated issue is due to the fact that your SQL string returns the same 50 records every time. You probably do not need to batch your updates for just 10,000 records, so running a single update is probably sufficient. If you disagree or do not understand, then please provide your code so we can better help you.
The 'logic' seems to be working as you intended.
the question is why are you trying to run the same update statement twice on the same data set?
I would suggest you clearly articulate what you are trying to update on each instance of the application, and make it different that the other one, then you will not have multiple of the same application updating the same rows.
or...
just don't run the same app twice and expect something different to occur.

Calling mysql.exe from Java

I am calling mysql.exe from Java to load a database. Because the process just hangs, I need to create a command file and pass in the username and password.
Example contents of command.bat:
mysql --user="%1" --password="%2" mydatabase < myscript.sql
The problem is that I cannot see the output of the mysql command to see if there were any errors. They display on the command line, but I cannot seem to capture them in a file for parsing or an InputStream.
How can I see the output of the mysql command?
NOTE: Calling mysql.exe directly from Java hangs because the mysql does not appear to be sending the information to the buffer.
NOTE: We are using mysql.exe instead of JDBC because we need to update things like triggers. In order to submit all the statements to the db, we would need to parse all the commands and pass them in one at a time.
NOTE: This is a running MySQL database that needs to be upgraded.
If you are only accessing this database from within Java, a better solution would be Connector/MXJ. This will allow you to simply make a well formed JDBC call, and the library will take care of the database startup for you automatically.
Basically, the jar file contains in instance (or, for multiple platforms, instances) of the mysql server executable. It also contains a skeleton where you can load prepopulated data for your database.
The first time you access the JDBC connection, it will pull the proper mysql server out of the jar, and create the database in the current directory (using the prepopulated data from above). Any changes from that point on will be persistent, as expected.
Here's some more info:
Launching via JDBC
Launching via a Java Object
Not sure why you can't view its output. Try making it output to a file, then use Java to read from the file at the same time.
I haven't tried this myself.
You should look at Process Builder. It lets you get a handle on the input/oputput and error stream.
The problem is that I cannot see the output of the mysql command to see if there were any errors. > They display on the command line, but I cannot seem to capture them in a file for parsing or an
InputStream.
Use 2>yourfilename
E.g.
mysql --user="%1" --password="%2" mydatabase < myscript.sql 2>myoutput.txt
should capture the STDERR (to where MySQL.exe sends its output here)
E.g.
mysql --user="%1" --password="%2" mydatabase < myscript.sql >myoutput.txt 2>&1
will capture both STDOUT and STDERR in the same file (=myoutput.txt).

Categories

Resources