package com.tis.genshinhikaku;
import java.sql.*;
public class readDabase {
String jdbcClassName="com.ibm.db2.jcc.DB2Driver";
String url="jdbc:db2://localhost:50000/SAMPLE:currentSchema=DB2ADMIN;";
String user="db2admin";
String password="admin";
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(String selectTableSQL) throws SQLException{
try {
Connection dbConnection = null;
Statement statement = null;
//String selectTableSQL = "SELECT * FROM DB2ADMIN.\"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());
}
}
}