12 changed files with 343 additions and 295 deletions
-
BIN.mvn/wrapper/maven-wrapper.jar
-
2.mvn/wrapper/maven-wrapper.properties
-
19src/main/java/com/feedback/it_asset/controller/APIController.java
-
55src/main/java/com/feedback/it_asset/controller/FeedbackController.java
-
4src/main/java/com/feedback/it_asset/entity/AssetCategory.java
-
8src/main/java/com/feedback/it_asset/entity/AssetCategoryQuestions.java
-
78src/main/java/com/feedback/it_asset/service/AssetDetailsService.java
-
4src/main/resources/application.properties
-
283src/main/resources/templates/dashboard.html
-
36src/main/resources/templates/gcc-asset-list.html
-
19src/main/resources/templates/gcc-complaint.html
-
2src/main/resources/templates/pending-complaint.html
@ -1,2 +0,0 @@ |
|||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip |
|||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar |
|||
@ -0,0 +1,78 @@ |
|||
package com.feedback.it_asset.service; |
|||
|
|||
import java.sql.Connection; |
|||
import java.sql.DriverManager; |
|||
import java.sql.PreparedStatement; |
|||
import java.sql.SQLException; |
|||
|
|||
import org.springframework.stereotype.Service; |
|||
|
|||
|
|||
@Service |
|||
public class AssetDetailsService { |
|||
|
|||
|
|||
private static final String SOURCE_JDBC_URL = "jdbc:mysql://localhost:3306/gcc_asset_details"; |
|||
private static final String DESTINATION_JDBC_URL = "jdbc:mysql://localhost:3306/it_assets"; |
|||
private static final String SOURCE_USERNAME = "root"; |
|||
private static final String SOURCE_PASSWORD = "root"; |
|||
private static final String DESTINATION_USERNAME = "root"; |
|||
private static final String DESTINATION_PASSWORD = "root"; |
|||
|
|||
public void migrateData() { |
|||
try { |
|||
// Load the JDBC driver |
|||
Class.forName("com.mysql.cj.jdbc.Driver"); |
|||
|
|||
// Establish connections for source and destination databases |
|||
try ( |
|||
Connection sourceConnection = DriverManager.getConnection(SOURCE_JDBC_URL, SOURCE_USERNAME, SOURCE_PASSWORD); |
|||
Connection destinationConnection = DriverManager.getConnection(DESTINATION_JDBC_URL, DESTINATION_USERNAME, DESTINATION_PASSWORD) |
|||
) { |
|||
// SQL query to fetch data from the source schema |
|||
String sqlQuery = "SELECT ta.ASSET_ID, ta.ASSET_NO, td.DEPT_NAME, tl.LOC_NAME, tsu.SEC_USER_NAME " + |
|||
"FROM tbl_asset ta " + |
|||
"JOIN tbl_mas_dept td ON ta.DEPT_ID = td.DEPT_ID " + |
|||
"JOIN tbl_mas_loc tl ON ta.LOC_ID = tl.LOC_ID " + |
|||
"JOIN tbl_mas_sec_user tsu ON ta.SECUSER_ID = tsu.SEC_USER_ID "; |
|||
|
|||
|
|||
// Create a prepared statement for the source database |
|||
try (PreparedStatement preparedStatementSource = sourceConnection.prepareStatement(sqlQuery)) { |
|||
|
|||
// Execute the query in the source database |
|||
try (var resultSet = preparedStatementSource.executeQuery()) { |
|||
// SQL query to insert data into the destination schema for asset_data |
|||
String insertAssetDataQuery = "INSERT INTO gcc_asset_details (asset_id, asset_code, department_name, position, assign_person) VALUES (?, ?, ?, ?, ?)"; |
|||
|
|||
// SQL query to insert data into the destination schema for asset_category |
|||
// String insertAssetCategoryQuery = "INSERT INTO asset_category (category_name) VALUES (?)"; |
|||
|
|||
// Create prepared statements for the destination database |
|||
try (PreparedStatement preparedStatementDestinationAssetData = destinationConnection.prepareStatement(insertAssetDataQuery)) { |
|||
|
|||
// Process the result set and insert data into the destination schema |
|||
while (resultSet.next()) { |
|||
// Insert data into asset_data table |
|||
preparedStatementDestinationAssetData.setString(1, resultSet.getString("ASSET_ID")); |
|||
preparedStatementDestinationAssetData.setString(2, resultSet.getString("ASSET_NO")); |
|||
preparedStatementDestinationAssetData.setString(3, resultSet.getString("DEPT_NAME")); |
|||
preparedStatementDestinationAssetData.setString(4, resultSet.getString("LOC_NAME")); |
|||
preparedStatementDestinationAssetData.setString(5, resultSet.getString("SEC_USER_NAME")); |
|||
int rowsAffectedAssetData = preparedStatementDestinationAssetData.executeUpdate(); |
|||
System.out.println("Rows affected for asset_data: " + rowsAffectedAssetData); |
|||
|
|||
// Insert data into asset_category table |
|||
// preparedStatementDestinationAssetCategory.setString(1, resultSet.getString("category_name")); |
|||
// int rowsAffectedAssetCategory = preparedStatementDestinationAssetCategory.executeUpdate(); |
|||
// System.out.println("Rows affected for asset_category: " + rowsAffectedAssetCategory); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} catch (ClassNotFoundException | SQLException e) { |
|||
e.printStackTrace(); // Handle the exception appropriately |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue