|
 |
|
ช่วยอธิบายโค้ด Java + Oracle แต่ละบรรทัด ให้หน่อยค่ะ จะศึกษาแต่ไม่รู้ว่าโค้ดแต่ละบรรทัดใช้ทำอะไรบ้าง |
|
 |
|
|
 |
 |
|
จาก code มันไม่มีอะไรซะซ้อนเลยน่ะครับ ผมไม่รู้ละเอียดน่ะ แต่รู้ว่ามันแค่ เชื่อมต่อ Java Oracle ผ่าน ODBC และ select ข้อมูล loop มาแสดง
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
public class Test {
private static final String username = "KSDK"; // ประกาศตัวแปร username
private static final String password = "KSDK"; // ประกาศตัวแปร password
private static final String URL = "jdbc:oracle:thin:@172.16.19.156:1521:ksdk"; // ตัวนี้น่าจะเป็น Connection String ของ Odbc Oracle
public static void main(String[] args) throws Exception {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c = DriverManager.getConnection(URL, username, password);
Statement s =c.createStatement();
ResultSet rs = s.executeQuery("select sysdate from dual"); // เลือกข้อมูลจากตาราง dual
while(rs.next()){ // loop ข้อม
System.out.println("Date is : "+rs.getDate(1)); // loop แสดงข้อมูล
}
} catch (SQLException ex) {
System.out.println(ex); // กรณี error
}
}
}
|
 |
 |
 |
 |
Date :
2012-06-06 11:01:13 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณนะคะ พี่วิน
พอดียังไม่เคยเขียนเลย ยังไม่รู้เรื่องอะไรเลย
ขอถามอีกนิดนะคะ
สามบรรทัดบนใช่ทำอะไรคะ
|
 |
 |
 |
 |
Date :
2012-06-06 11:08:27 |
By :
pompam_angel |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|