In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Technical bulls, please consult java multithreading problem.
Due to the needs of the project, you need to migrate the table records from the oracle to the dept2, and the dept and dept2 table structures are the same.
Imagine:
Query:
Statement stmt = conn.createStatement (
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)
ResultSet rs = stmt.executeQuery ("select * from dept")
The total number of records is obtained through rs.last ();, and then all records are migrated by multithreading through this total number.
Insert:
PreparedStatement pstmt = null
String psql = "insert into dept2 values (?)"
Pstmt = conn.prepareStatement (psql)
Where index is the index value of the rs result set. When index=1, it represents the first value of rs.next ().
Rs.absolute (index)
Pstmt.setInt (1, rs.getInt (1))
Pstmt.setString (2, rs.getString (2))
Pstmt.setString (3, rs.getString (3))
Pstmt.addBatch ()
I do not know much about multithreading, tried many times, failed to achieve multithreading migration data, hope to have expert advice. Thank you!
Public class ConcurrentTestPreparedStmt
{
Public static int totalRowNum
Public static int index = 1
Public static boolean isFinish
Public static void main (String [] args) throws Exception
{
Class.forName ("oracle.jdbc.driver.OracleDriver")
String url = "jdbc:oracle:thin:@192.168.5.201:1521:orcl"
String user = "scott"
String password = "tiger"
String sql = "select * from dept"
Connection conn = DriverManager.getConnection (url, user, password)
/ * *
* read
, /
Statement stmt = conn.createStatement (
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)
ResultSet rs = stmt.executeQuery (sql)
/ * *
* write
* use batch processing
, /
PreparedStatement pstmt = null
String psql = "insert into testpstmt values (?)"
Pstmt = conn.prepareStatement (psql)
/ / rs.next as long as it is true, indicate the number of records in the table
Rs.last ()
TotalRowNum = rs.getRow ()
Int I = 0
/ / where the problem lies, when I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.