javadb/org/homelinux/largo/sql/client/DBClient.java
changeset 105 c19e37122deb
parent 100 a6d2add085d7
child 123 07b2c0b991af
equal deleted inserted replaced
104:b59f1c9895db 105:c19e37122deb
    32 		statement = connection.createStatement ();
    32 		statement = connection.createStatement ();
    33 	}
    33 	}
    34 
    34 
    35 	/**
    35 	/**
    36 	 * Default Konstruktor to connect to my DataPool
    36 	 * Default Konstruktor to connect to my DataPool
    37 	 */ 
    37 	 */
    38 	public DBClient (String jndiResource) throws Exception {
    38 	public DBClient (String jndiResource) throws Exception {
    39 		Context ctx = new InitialContext ();
    39 		Context ctx = new InitialContext ();
    40 		DataSource ds = (DataSource) ctx.lookup (jndiResource);
    40 		DataSource ds = (DataSource) ctx.lookup (jndiResource);
    41 
    41 
    42 		connection = ds.getConnection ();
    42 		connection = ds.getConnection ();
    43 		statement = connection.createStatement ();
    43 		statement = connection.createStatement ();
    44 	}
    44 	}
    45 
    45 
    46 	/**
    46 	/**
    47 	 * Default Konstruktor to connect to my database with auth-data
    47 	 * Default Konstruktor to connect to my database with auth-data
    48 	 */ 	 
    48 	 */
    49 	public DBClient (String driver, String dbURL, String username, String password) throws Exception {
    49 	public DBClient (String driver, String dbURL, String username, String password) throws Exception {
    50 		this.driver = driver;
    50 		this.driver = driver;
    51 		this.dbURL = dbURL;
    51 		this.dbURL = dbURL;
    52 
    52 
    53 		this.username = username;
    53 		this.username = username;
    54 		this.password = password;
    54 		this.password = password;
    55 
    55 
    56 		Class.forName (driver);
    56 		Class.forName (driver);
    57 		connection = DriverManager.getConnection (dbURL, username, password);
    57 		connection = DriverManager.getConnection (dbURL, username, password);
    58 		statement = connection.createStatement ();
    58 		statement = connection.createStatement ();
    59 	} 
    59 	}
    60 
    60 
    61 	public void close () throws Exception {
    61 	public void close () throws Exception {
    62 		connection.close ();
    62 		connection.close ();
    63 	} 
    63 	}
    64 
    64 
    65 	public String getColumn (int pos) throws Exception {
    65 	public String getColumn (int pos) throws Exception {
    66 		return resultset.getString (pos);
    66 		return resultset.getString (pos);
    67 	} 
    67 	}
    68 
    68 
    69 	public String getColumn (String name) throws Exception {
    69 	public String getColumn (String name) throws Exception {
    70 		return resultset.getString (name);
    70 		return resultset.getString (name);
    71 	} 
    71 	}
    72 
    72 
    73 	public Connection getConnection () {
    73 	public Connection getConnection () {
    74 		return connection;
    74 		return connection;
    75 	} 
    75 	}
    76 
    76 
    77 	public String getDbURL () {
    77 	public String getDbURL () {
    78 		return dbURL;
    78 		return dbURL;
    79 	}
    79 	}
    80 
    80 
    94 		return resultset.next ();
    94 		return resultset.next ();
    95 	}
    95 	}
    96 
    96 
    97 	public void query (String query) throws Exception {
    97 	public void query (String query) throws Exception {
    98 		resultset = statement.executeQuery (query);
    98 		resultset = statement.executeQuery (query);
    99 	} 
    99 	}
   100 
   100 
   101 	public void setConnection (Connection connection) {
   101 	public void setConnection (Connection connection) {
   102 		this.connection = connection;
   102 		this.connection = connection;
   103 	}
   103 	}
   104 
   104