package com.dlut.zxf;
import java.sql.*;
public class Conn {
public static void main(String[] args) {
String classDriver = "oracle.jdbc.driver.OracleDriver";
String dbURL = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "michael";
String password = "michael";
String sql = "select id from student";
Connection conn = null;
Statement state = null;
ResultSet res = null;
try
{
Class.forName(classDriver);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
conn = DriverManager.getConnection(dbURL, user, password);
state = conn.createStatement();
res = state.executeQuery(sql);
while (res.next())
{
System.out.println(res.getString("id"));
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
|