Guest User

Untitled

a guest
Dec 9th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  5. <hibernate-configuration>
  6.  
  7. <session-factory>
  8. <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  9.  
  10. <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
  11. <property name="hibernate.connection.username">sample</property>
  12. <property name="hinernate.connection.password">root</property>
  13. <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
  14.  
  15. <property name="show_sql">true</property>
  16.  
  17. <mapping class="com.model.Student" resource="com/model/Student.hbm.xml" />
  18. </session-factory>
  19.  
  20. public class OracleJDBCExample {
  21.  
  22. public static void main(String[] args) {
  23.  
  24. try {
  25.  
  26. Class.forName("oracle.jdbc.driver.OracleDriver");
  27.  
  28. } catch (ClassNotFoundException e) {
  29.  
  30. System.out.println("Where is your Oracle JDBC Driver?");
  31. e.printStackTrace();
  32. return;
  33.  
  34. }
  35.  
  36. System.out.println("Oracle JDBC Driver Registered!");
  37.  
  38. Connection connection = null;
  39.  
  40. try {
  41.  
  42. connection = DriverManager.getConnection(
  43. "jdbc:oracle:thin:@localhost:1521:xe", "sample", "root");
  44.  
  45. PreparedStatement ps=connection.prepareStatement("select * from Employee");
  46. System.out.println("*******");
  47. ResultSet rs=ps.executeQuery();
  48. System.out.println("--->"+rs.toString());
  49. if(rs.next()) {
  50. System.out.println("---> "+rs.getString(1));
  51. }
  52. rs.close();
  53. ps.close();
  54.  
  55. } catch (SQLException e) {
  56.  
  57. System.out.println("Connection Failed! Check output console");
  58. e.printStackTrace();
  59. return;
  60.  
  61. }
  62.  
  63. if (connection != null) {
  64. System.out.println("You made it, take control your database now!");
  65. } else {
  66. System.out.println("Failed to make connection!");
  67. }
  68.  
  69. }
Add Comment
Please, Sign In to add comment