473,545 Members | 2,081 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 10858
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
2897
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 application directly to a text file (CSV). So far as I know, there is no way to make this application talk directly to the MySQL server. We're...
0
1534
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 sub-directory and for each file listed insert a record into a temporary table. Can anyone help? My code is as follows.... SQL Stored Procedure...
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 'Templates' so that they would not have to re-enter alot of the information. So from a db perspective I would have to re-insert these records into the...
5
6602
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 transactionsize)? any suggestions? thanks a lot!! chris
4
4839
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 retrieve out new records from "ceo_email" and "contact_email" column after e.g 25.July.07
0
4436
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 tables are all linked with the field 'member_id', which is an auto-increment field in the parent table ('members'). I've been able to input multiple...
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. e.g my excel sheet has filled first 20 rows and then i want to insert the new records in the excel sheet starts from 21st row is any idea about...
7
7606
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 number), buy_id, item_name, price, quantity,...) Target: - Make a main-form of table with sub-form of table to insert/update records for both...
12
16097
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 form. Then depending on the difference between the start and end dates, that number of text boxes have their visibility set to TRUE and are displayed...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3450
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1884
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 we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.