473,505 Members | 16,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert several records simultaneously with java and mysql

1 New Member
Dear Community a pleasure to greet you, I am reading several HoldinRegister type registers for that I am using easymodbus in total will be 150 registers that must be read and saved each time a Coil type register changes from 0 to 1, the reading of these registers is done as follows:

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) throws Exception
  2. {
  3.     ModbusClient modbusClient = new ModbusClient();
  4.     modbusClient.Connect("127.0.0.1", 502);
  5.     int[] inputRegisters = modbusClient.ReadHoldingRegisters(0, 149);
  6.     for (int i=0; i < inputRegisters.length; i++)
  7.         System.out.println("Holding Register  #"+i+": "+inputRegisters[i]);
  8. }
The values of the registers are updated only when the Coil changes its value, then save those registers in the database, I think this is better because if they would be updating all the time it would consume too many resources.

My question now is how can I do to save that amount of data at the same time, searching the net I found an example using FOR but I don't understand very well how to integrate it since I can't make it work.

Expand|Select|Wrap|Line Numbers
  1. String SQL = "INSERT INTO ingredients(date,regnumb,regval)"
  2.     + "values (?,?,?)";
  3.  
  4.     mensaje="data inserted correctly";
  5.     try{
  6.         PreparedStatement sqls = (PreparedStatement) conn.prepareStatement(SQL);
  7.  
  8.         int rows =4;
  9.  
  10.  
  11.         for(int i = 0; i
  12.         sqls.setString(1, date);
  13.         sqls.setString(2, regnumb);          
  14.         sqls.setString(5, regval);
  15.         sqls.addBatch();
  16. } sqls.executeBatch();
thank you very much for your attention
Apr 1 '22 #1
1 10845
dev7060
639 Recognized Expert Contributor
I haven't worked with Modbus communication or its libraries. I can provide generic advice. Proceed if it sounds useful to you.


The values of the registers are updated only when the Coil changes its value, then save those registers in the database
How does the 'Coil' change its value? If there's an event listener provided in the library, the code to update the database can be put in the function.

Expand|Select|Wrap|Line Numbers
  1. String SQL = "INSERT INTO ingredients(date,regnumb,regval)"
  2.     + "values (?,?,?)";
  3.  
  4.     mensaje="data inserted correctly";
  5.     try{
  6.         PreparedStatement sqls = (PreparedStatement) conn.prepareStatement(SQL);
  7.  
  8.         int rows =4;
  9.  
  10.  
  11.         for(int i = 0; i
  12.         sqls.setString(1, date);
  13.         sqls.setString(2, regnumb);          
  14.         sqls.setString(5, regval);
  15.         sqls.addBatch();
  16. } sqls.executeBatch();
I see syntax errors.

My question now is how can I do to save that amount of data at the same time, searching the net I found an example using FOR but I don't understand very well how to integrate it since I can't make it work.
What do you want to 'integrate' with what? What isn't working? What errors do you see? You may want to mention the specific database schema or columns and what updates are to be made and where.
Apr 9 '22 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2894
by: Frank Pryor | last post by:
Hello, I'd appreciate suggestions as I hash out my idea. Perhaps I'm going about this the wrong way. I have users using a third party windows application. They can export data from this...
0
1530
by: Ian Macey | last post by:
I am wanting to Insert multiple records into a table, and although I have some working code I feel that there must be a better way. The purpose of the code is to do a directory listing of a...
2
1775
by: Tom Gao | last post by:
I have a problem. The project that I'm working on requires me to duplicate records. As in a series of records are entered into the system the user then click on a button to make these as...
5
6596
by: Chris | last post by:
i am looking for the fastest way to insert several 1000 trx int oracle. is there a faster way, then using a DataAdapter? is there a possibilty to execute a bulk load (or batchwise insert with...
4
4832
by: xoozlez | last post by:
Hi there, How do I insert new records from a dbo table to another table? This is what I have: 1 dbo_company 1 Member (table) I made a query in dbo_company with the criteria I only want to...
0
4434
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
14
2482
by: veer | last post by:
can any one help by providing the method inserting the records in excel file because i created it all it works fine but i have no idea about how to insert new records in the existing excel file....
7
7598
by: ndhvu | last post by:
Tables: Buy_Header and Buy_Detail. - Buy_Header: info. of each buy (buy_id(PK, auto number), date, shop, bought_by, ...) - Buy_Detail: info. of each item from each buy (buy_detail_id(PK, auto...
12
16093
by: Blake Rice | last post by:
Hi everyone! This is my first time posting here, so here goes. THE SITUATION: I have a form that has a start date, end date, project number, and total volume. These values are pulled from another...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.