Advertisement
Guest User

Untitled

a guest
Oct 8th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.sql.CallableStatement;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.Types;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.sql.PreparedStatement;
  9. import java.sql.CallableStatement;
  10. import java.sql.Struct;
  11. import java.sql.Array;
  12. import java.math.BigDecimal;
  13. import java.sql.*;
  14.  
  15. public class testJava {
  16.  
  17.   public static void main(String[] args) throws Exception {
  18.  
  19.     Class.forName("com.edb.Driver");
  20.     Connection connection = null;
  21.     String st = null;
  22.  
  23.     String url = "jdbc:edb://127.0.0.1:5432/mc";
  24.     String user = "enterprisedb";
  25.     String password = "o1234";
  26.     connection = DriverManager.getConnection(url,user,password);
  27.  
  28.     try {
  29.       String commandText = "SELECT file FROM xmltest";
  30.       PreparedStatement cs = connection.prepareStatement(commandText);
  31.       ResultSet rs = cs.executeQuery();
  32.       while (rs.next()) {
  33.         String s = rs.getString("file");
  34.         System.out.println("File: " + s);
  35.         }
  36.     } catch (SQLException ex)
  37.     {
  38.       System.out.println("State: " + ex.getSQLState() +
  39.                          "\nMessage: " + ex.getMessage());
  40.  
  41.     }
  42.  
  43.     finally {
  44.       try {
  45.  
  46.         if (connection != null)
  47.  
  48.         {
  49.           connection.close();
  50.         }
  51.  
  52.       } catch (SQLException ex)
  53.       {
  54.         System.out.println(ex);
  55.       }
  56.     }
  57.   }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement