how to get new records from MySQL using java - 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.

Related

how to get a user confirmation in the middle of a transaction?

I've been working on a transactional services which is used as a part of core banking project. In many services, before inserting any records in my database, I should run several validation on the records. It is also true for editing the records which are already exist in the database.
But sometimes in order to update a record in an specified table, we should change records in other tables which are related to the specified table. Consequently, we need a user confirmation to change records on other tables. But the problem is I don't know how could I get a user confirmation in client while I run a transaction in the server. Is it possible to tackle this problem using sending message between client and server through rabbitMq?
I will be appreciate if any one explain any solution using clear sample.
When I would need to implement this, I would do it in an other way (I do not know if this works for your scenario).
I would first let the user input his data,
then I would do a try run and check which additional confirmations are needed I would also save (in the user session) all relevant constraints that are determined while the try run
then I would ask the user for the additional confirmations determined while the try run
then I would do the real-run, and use the saved constraint checks to be save that nothing relevant has been changed meanwhile.
(If there is a relevant change in the data between try- and real-rung detected, I would apologise and start the process with step 2 again)
but this only works if you do not have so many "meanwhile changes"

MySQL Dump File is Excluding almost all Insert Statements

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.

Java program doing Neo4j queries is not saving data I need

I am having a problem with my Java program using a GraphDatabaseService.
At start, I was using different paths for http://localhost:7744/webadmin and my Java program.
Then, I fixed it, using this question here: Neo4j - read and save data.
So, this is not the problem!
Then, I open my DB, put some nodes on it. I searched with a query, and it just returned the nodes I created. Then I shutdown my DB.
But everytime I rerun the program again, the nodes I created before are not there anymore!
Then I go to webadmin, the nodes aren't there, too! So I decided to first create the nodes on webadmin console, and query them on console, it worked!
After this, I tried to run a query on my Java program to look for these console nodes, and it worked, they were shown.
Then again, on the Java program, I run a query, create some new nodes, then run a query again. The first query returns the console nodes, the second returns the console nodes + the new ones created on the Java program.
But I just have again the same problem. On a new Java program run, it doesn't show the new nodes (the Java program ones), and neither on webadmin console.
Long story short, seems like my program is not saving the data (I might be wrong). You guys know any way to fix it?
I solved this!
Seems like I wasn't doing a tx.finish() in my Transaction tx, because I was using Eclipse, and it showed a warning saying that this method (tx.finish()) was deprecated, so I decided to remove it. Then I put it back again, ignoring the warning, and it solved my problem!
Just posting the answer here so I could help it if someone has the same problem.

Trying to set terminal width/height for a program running on a tomcat server

So I'm trying to get data on a program through linux, and the only way the makers have given is to run a script that runs some internal commands which run prints, and then it saves them to file. The only issue is that the way it prints out the data is determinate of the terminal width/height, making it potentially unparsable if run at weird size.
I'm trying to run java code from tomcat a tomcat server that will call this script and then create the file so that I can parse the data. However, when I run the script this way, my "stty columns 10000" commands fail to change the terminal size, such that the print is stunted.
The end goal is to run this as an automated task, so there won't even be a terminal and I'm wondering how this will effect the prints. I'm working on getting that up and running, but I figured I'd post this sooner than later to see if anyone has any solutions.
I've done the crossed out stuff above, and the program uses the linux terminal's default sizes (80 columns, 24 rows). I managed to use stty before starting the java, and then the program reported 80 columns and 134555573 rows... lol. This stuff is all being run on root and set at boot.
Thank you

JasperServer Error - Unable to get next record

I have a very simple report that runs perfectly on in iReports (4.5.0) on my workstation. When I upload it JasperServer CE (4.5.0) I get the following error.
1 - Unable to get next record.
java.lang.Exception: 1 - Unable to get next record.
at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReport(WSClient.java:403)
at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReport(WSClient.java:320)
at com.jaspersoft.ireport.jasperserver.ReportRunner.run(ReportRunner.java:70)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
There are other much more complex queries and reports that are running on the JasperServer without problem. The database system is Basis/Pro5 running BBJ (Business Basic Java). I am connected to the database in iReports and JasperServer using the same native JDBC Basis driver (BBjJDBS.jar). JasperServer is running on the same RHEL box as the BBj database. Jasper server is installed as a bundle using both the built in DB and Tomcat. No other known conflicts exist.
The following single table query is designed to get the sum totals of a transaction for a given month. The report has one detail section which just prints the query output.
SELECT
Month(INHI.TRANSACTION_DATE) AS TransMonth,
admin.INHI.ITEM_ID,
admin.INHI.TRANSACTION_TYPE,
SUM(admin.INHI.TRANS_QUANTITY) as TransQty
FROM
admin.INHI
WHERE
admin.INHI.ITEM_ID = 'R-CBSH-3300'
AND (
admin.INHI.TRANSACTION_TYPE = 'B2'
OR admin.INHI.TRANSACTION_TYPE = 'P1')
AND admin.INHI.TRANSACTION_DATE BETWEEN '2012-01-01' AND '2012-03-31'
GROUP BY
Month(INHI.TRANSACTION_DATE),
admin.INHI.ITEM_ID,
admin.INHI.TRANSACTION_TYPE
Order By
admin.INHI.TRANSACTION_TYPE
I have looked all over to try and find additional trouble shooting tips and have ran out of options to try. Any guidance is greatly appreciated.
In my case I was able to get an extended error from the JasperServer web interface which lead me to an Date/Time issue. The crux of the whole problem was the "Order By" clause. Once I removed the order by the query worked fine.
You can also get this error if you pass a closed result set as the data source for the report.
In my case I passed the JasperReportBuilder object around and somewhere I (prematurely) closed the Connection object that the result set was bound to.

Categories

Resources