Advertisement
Guest User

Untitled

a guest
Jun 1st, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. package cashetest;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.Properties;
  8.  
  9. import com.intersys.jdbc.CacheDataSource;
  10.  
  11. public class Database {
  12.  
  13.     public static Connection getConnection() {
  14.         String url = "jdbc:Cache://127.0.0.1:1972/MARKET";
  15.         String username = "_SYSTEM";
  16.         String password = "celeron015";
  17.         try {
  18.             java.sql.Driver drv = java.sql.DriverManager.getDriver(url);
  19.             System.out.println("prosao2");
  20.             java.util.Properties props = new Properties();
  21.             props.put("user", username);
  22.             props.put("password", password);
  23.             Connection dbconnection = drv.connect(url, props);
  24.             System.out.println("prosao3");
  25.             return dbconnection;
  26.         } catch (Exception ex) {
  27.             ex.printStackTrace();
  28.         }
  29.         return null;
  30.     }
  31.  
  32.     public static Connection getConnection2() {
  33.         try {
  34.             CacheDataSource ds = new CacheDataSource();
  35.             ds.setURL("jdbc:Cache://127.0.0.1:1972/Samples");
  36.             ds.setUser("_SYSTEM");
  37.             ds.setPassword("celeron015");
  38.             Connection dbconnection = ds.getConnection();
  39.             return dbconnection;
  40.         } catch (Exception ex) {
  41.             ex.printStackTrace();
  42.         }
  43.         return null;
  44.     }
  45.  
  46.     public static void main(String[] args) {
  47.         Connection c = getConnection();
  48.         String sql = "Select name from Market.model.Item Order By Name";
  49.         int scroll = ResultSet.TYPE_SCROLL_SENSITIVE;
  50.         int update = ResultSet.CONCUR_UPDATABLE;
  51.  
  52.         PreparedStatement pstmt;
  53.         try {
  54.             pstmt = c.prepareStatement(sql, scroll, update);
  55.             java.sql.ResultSet rs = pstmt.executeQuery();
  56.             while (rs.next()) {
  57.                 System.out.println("\n Old name = " + rs.getString("Name"));
  58.             }
  59.         } catch (SQLException e) {
  60.             // TODO Auto-generated catch block
  61.             e.printStackTrace();
  62.         }
  63.  
  64.         if (c != null) {
  65.             System.out.println(c.toString());
  66.         } else {
  67.             System.out.println("null je");
  68.         }
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement