hikaku.java
package com.tis.genshinhikaku;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
public class hiKaku {
public static void main(String[] args) throws IOException, SQLException {
readCsvFile readCsvFile = new readCsvFile();
readDabase rData = new readDabase();
readCsvFile.readCsv();
//rData.connectDB();
rData.selectRecordsFromDbStudent();
}
}
objectInfo.java
package com.tis.genshinhikaku;
public class objectInfo {
private String tableNameNew;
private String tableNameOld;
private String tableNameResult;
private String objectName;
private String objectKey;
private String objectFlag;
private String table;
public String getTableNameNew() {
return tableNameNew;
}
public void setTableNameNew(String tableNameNew) {
this.tableNameNew = tableNameNew;
}
public String getTableNameOld() {
return tableNameOld;
}
public void setTableNameOld(String tableNameOld) {
this.tableNameOld = tableNameOld;
}
public String getTableNameResult() {
return tableNameResult;
}
public void setTableNameResult(String tableNameResult) {
this.tableNameResult = tableNameResult;
}
public String getObjectName() {
return objectName;
}
public void setObjectName(String objectName) {
this.objectName = objectName;
}
public String getObjectKey() {
return objectKey;
}
public void setObjectKey(String objectKey) {
this.objectKey = objectKey;
}
public String getObjectFlag() {
return objectFlag;
}
public void setObjectFlag(String objectFlag) {
this.objectFlag = objectFlag;
}
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
}
}
readCsvFile.java
package com.tis.genshinhikaku;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class readCsvFile {
public void readCsv() throws IOException {
String line = "";
String file = "D://IBM/csv/data.txt";
objectInfo info = new objectInfo();
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
info.setTable(br.readLine());
info.setObjectName(br.readLine());
info.setObjectKey(br.readLine());
info.setObjectFlag(br.readLine());
} catch (FileNotFoundException e) {
//Some error logging
}
}
}
readDatabase.java
package com.tis.genshinhikaku;
import java.sql.*;
public class readDabase {
String jdbcClassName="com.ibm.db2.jcc.DB2Driver";
String url="jdbc:db2://localhost:50000/sample";
String user="db2admin";
String password="admin";
Statement stmt;
ResultSet rs;
public Connection connectDB () {
Connection connection = null;
try {
//Load class into memory
Class.forName(jdbcClassName);
//Establish connection
connection = DriverManager.getConnection(url, user, password);
System.out.println("Connecting!.");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
public void closeDbConnect(Connection conn) {
if (conn != null) {
System.out.println("Connected successfully.");
try {
conn.close();
System.out.println("Connected successfully.");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void selectRecordsFromDbStudent() throws SQLException{
try {
Connection dbConnection = null;
Statement statement = null;
String selectTableSQL = "SELECT * FROM DYL.'student'";
dbConnection = connectDB();
statement = dbConnection.createStatement();
System.out.println(selectTableSQL);
ResultSet rs = statement.executeQuery(selectTableSQL);
while (rs.next()) {
System.out.println("get records");
}
}catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
网友评论