import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Select1 {
private static final String url = "jdbc:oracle:thin:@172.21.10.56:1521:ora";
private static final String user = "AZ_USER";
private static final String password = "AZ_PSWD";
private static Connection con;
private static Statement stmt;
private static ResultSet rs;
public static void main(String args[]) {
String query = "select count(*) from sysuser";
try {
con = DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
rs = stmt.executeQuery(query);
while (rs.next()) {
int count = rs.getInt(1);
System.out.println("Total number of users: " + count + ".");
}
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
} finally {
try { con.close(); } catch(SQLException se) { /*can't do anything */ }
try { stmt.close(); } catch(SQLException se) { /*can't do anything */ }
try { rs.close(); } catch(SQLException se) { /*can't do anything */ }
}
}
}
Компиляция:
javac Select1.javaЕсли поместить "ojdbc6.jar" в папку .\lib\ тогда команда запуска будет выглядеть так:
java -cp .;.\lib\ojdbc6.jar Select1или так:
java -cp .;.\lib\* Select1
Комментариев нет:
Отправить комментарий