Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cashetest;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Properties;
- import com.intersys.jdbc.CacheDataSource;
- public class Database {
- public static Connection getConnection() {
- String url = "jdbc:Cache://127.0.0.1:1972/MARKET";
- String username = "_SYSTEM";
- String password = "celeron015";
- try {
- java.sql.Driver drv = java.sql.DriverManager.getDriver(url);
- System.out.println("prosao2");
- java.util.Properties props = new Properties();
- props.put("user", username);
- props.put("password", password);
- Connection dbconnection = drv.connect(url, props);
- System.out.println("prosao3");
- return dbconnection;
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return null;
- }
- public static Connection getConnection2() {
- try {
- CacheDataSource ds = new CacheDataSource();
- ds.setURL("jdbc:Cache://127.0.0.1:1972/Samples");
- ds.setUser("_SYSTEM");
- ds.setPassword("celeron015");
- Connection dbconnection = ds.getConnection();
- return dbconnection;
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return null;
- }
- public static void main(String[] args) {
- Connection c = getConnection();
- String sql = "Select name from Market.model.Item Order By Name";
- int scroll = ResultSet.TYPE_SCROLL_SENSITIVE;
- int update = ResultSet.CONCUR_UPDATABLE;
- PreparedStatement pstmt;
- try {
- pstmt = c.prepareStatement(sql, scroll, update);
- java.sql.ResultSet rs = pstmt.executeQuery();
- while (rs.next()) {
- System.out.println("\n Old name = " + rs.getString("Name"));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if (c != null) {
- System.out.println(c.toString());
- } else {
- System.out.println("null je");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement