Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
- <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
- <property name="hibernate.connection.username">sample</property>
- <property name="hinernate.connection.password">root</property>
- <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
- <property name="show_sql">true</property>
- <mapping class="com.model.Student" resource="com/model/Student.hbm.xml" />
- </session-factory>
- public class OracleJDBCExample {
- public static void main(String[] args) {
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch (ClassNotFoundException e) {
- System.out.println("Where is your Oracle JDBC Driver?");
- e.printStackTrace();
- return;
- }
- System.out.println("Oracle JDBC Driver Registered!");
- Connection connection = null;
- try {
- connection = DriverManager.getConnection(
- "jdbc:oracle:thin:@localhost:1521:xe", "sample", "root");
- PreparedStatement ps=connection.prepareStatement("select * from Employee");
- System.out.println("*******");
- ResultSet rs=ps.executeQuery();
- System.out.println("--->"+rs.toString());
- if(rs.next()) {
- System.out.println("---> "+rs.getString(1));
- }
- rs.close();
- ps.close();
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return;
- }
- if (connection != null) {
- System.out.println("You made it, take control your database now!");
- } else {
- System.out.println("Failed to make connection!");
- }
- }
Add Comment
Please, Sign In to add comment