package untitled1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import com.borland.jbcl.layout.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1
extends JFrame {
JPanel contentPane;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
display();
}
catch (Exception e) {
e.printStackTrace();
}
}
public final static String url= "jdbc:oracle:thin:@190.1.117.149:1521:orcl";
public final static String us = "hpmsuser";
public final static String pw = "hpmsuser";
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
private void display() {
// TODO Auto-generated method stub
String driver = "oracle.jdbc.driver.OracleDriver";
//String url = "jdbc:odbc:EDURA;UID=hpmsuser;PWD=hpmsuser";
Connection conn = null;
String sql =
"SELECT * FROM USERS";
try {
//Driver Loading
Class.forName(driver);
System.out.println("Driver Loading Sucess");
}
catch (ClassNotFoundException ex) {
System.out.println("Class Not Found");
}
Statement stmt = null;
ResultSet rs = null;
try {
//DB Connection
conn = DriverManager.getConnection(url,us,pw);
//Statement Object 생성
stmt = conn.createStatement();
//Query 실행
rs = stmt.executeQuery(sql);
while (rs.next()) {
String OBJECT_ID = rs.getString("OBJECT_ID");
String CLASS_ID = rs.getString("CLASS_ID");
String LOGIN = rs.getString("LOGIN");
jTextField1.setText(OBJECT_ID);
jTextField2.setText(CLASS_ID);
jTextField3.setText(LOGIN);
}
}
catch (SQLException ex) {
System.out.println(ex.toString());
}
finally {
try {
if (rs != null) rs.close();
if (conn != null) conn.close();
}
catch (SQLException ex) {
System.out.println(ex.toString());
}
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
jTextField1.setText("jTextField1");
contentPane.setLayout(xYLayout1);
this.setLocale(java.util.Locale.getDefault());
this.setSize(new Dimension(400, 300));
this.setState(Frame.NORMAL);
this.setTitle("Frame Title");
contentPane.setVerifyInputWhenFocusTarget(true);
jTextField2.setText("jTextField2");
jTextField3.setText("jTextField3");
contentPane.add(jTextField1, new XYConstraints(45, 39, 99, 44));
contentPane.add(jTextField2, new XYConstraints(47, 106, 93, 31));
contentPane.add(jTextField3, new XYConstraints(44, 152, 99, 33));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
'SQL > DBMS설정,커넥팅' 카테고리의 다른 글
[본문스크랩] [팁] ADO 커넥션 스트링 모음 (0) | 2014.06.11 |
---|