java 코드로 was와 db 연결에 문제 없는지 테스트
1. java 코드 (DBConnection.java)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Date;
public class DBConnection
{
public static void main(String args[])
{
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
String sQuery = " select * from test.test";
try {
String user = "testuser";
String passwod = "test";
String url = "jdbc:oracle:thin:@10.10.10.10:1521:test";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, user, password);
System.out.println("Database connection ok...\n");
pstm = conn.prepareStatement(sQuery);
rs = pstm.executeQuery();
while(rs.next()) {
int id = rs.getInt(1);
String name = rs.getString(2);
Date credt = rs.getDate(3);
String result = ( id + "," + "name" + "," + credt);
System.out.println(result);
}
} catch (ClassNotFoundException ce) {
System.out.println("DB driver class not found : " + ce.toString());
} catch (SQLException se) {
System.out.println("DB SQL exception : " + se.toString());
} catch (Exception e) {
System.out.println("Other error");
e.printStackTrace();
} finally {
try {
if ( rs != null ) rs.close();
if ( pstm != null ) pstm.close();
if ( conn != null ) conn.close();
} catch(Exception e) {
throw new RuntimeException(e.getMessage());
}
}
}
}
* DB table
create table test (
id number,
name varchar2(10,
reg_dt datetime default sysdate,
constraint pk_id primary key(id) using index tablespace users
) tablespace users;
2. java code complile : javac DBConnection.java
3. java 수행
export PATH=$PATH:/user/local/java/bin
export CLASSPATH=.:/tmp/ojdbc6.jar
java DBConnection (결과출력 되면 연결에 문제 없음)
or java -cp .:/tmp/ojdbc6.jar DBConnection
'RDB > Oracle' 카테고리의 다른 글
oracle amm 설정 (0) | 2021.02.16 |
---|---|
oracle 19c 설치 (0) | 2020.12.09 |
oracle rman duplicate recovery 방식 (0) | 2020.08.19 |
oracle silent install (0) | 2020.07.22 |
oracle 데이터 이관후 정합성 체크 (0) | 2020.07.22 |