javadb/org/homelinux/largo/sql/client/DBClient.java
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Nov 2010 04:05:14 +0100
changeset 153 b223089872b6
parent 135 f837cf975e95
permissions -rw-r--r--
ipv6 support added committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     1
/**
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     2
 * Simple Database Client for Java
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     3
 *
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     4
 */
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     5
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
package org.homelinux.largo.sql.client;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     8
import java.util.List;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     9
import java.util.ArrayList;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    10
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
import java.sql.Connection;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
import java.sql.DriverManager;
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    13
import java.sql.DatabaseMetaData;
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
import java.sql.ResultSet;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
import java.sql.Statement;
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    16
import java.sql.SQLException;
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
import javax.naming.Context;
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    19
import javax.naming.NamingException;
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
import javax.naming.InitialContext;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
import javax.sql.DataSource;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
public class DBClient {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
	private Connection connection;
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    25
	private DatabaseMetaData metadata;
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
	private Statement statement;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
	private ResultSet resultset;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
	private String driver, username, password;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
	private String dbURL;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
	/**
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    33
	 * Constructor to connect to a database with a specific driver
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    34
	 * and connection string
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
	 */
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    36
	public DBClient (String driver, String dbURL, String username, String password) throws ClassNotFoundException, SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    37
		this.driver = driver;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    38
		this.dbURL = dbURL;
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
		Class.forName (driver);
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    41
		connect (username, password);
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
	/**
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    45
	 * Constructor to connect to a database with a specific driver
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    46
	 * and connection string
105
c19e37122deb Removed Whitespace errors in DBClient.java
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 100
diff changeset
    47
	 */
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    48
	public DBClient (String driver, String dbURL) throws ClassNotFoundException, SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    49
		this (driver, dbURL, null, null);
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    50
	}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    51
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    52
	/**
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    53
	 * Default Constructor to connect to my database
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    54
	 */
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    55
	public DBClient () throws ClassNotFoundException, SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    56
		this ("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:clubstatistik", null, null);
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    57
	}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    58
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    59
	/**
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    60
	 * Constructor to connect to a DataSource on an AppServer
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    61
	 */
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    62
	public DBClient (String jndiResource) throws NamingException, SQLException {
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
		Context ctx = new InitialContext ();
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
		DataSource ds = (DataSource) ctx.lookup (jndiResource);
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    66
		connection = ds.getConnection ();
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    67
		statement = connection.createStatement ();
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    69
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    70
        protected void connect(String user, String pass) throws SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    71
		assert (connection == null) : "CONNECT: Already connected";
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    73
		this.username = user;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    74
		this.password = pass;
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    75
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    76
		connection = DriverManager.getConnection (dbURL, username, password);
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    77
		metadata = connection.getMetaData();
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    78
		statement = connection.createStatement ();
105
c19e37122deb Removed Whitespace errors in DBClient.java
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 100
diff changeset
    79
	}
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    80
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    81
	public void disconnect () throws SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    82
		if (connection == null)
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    83
			throw new SQLException ("DISCONNECT: Not connected");
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    84
		else
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    85
			connection.close ();
105
c19e37122deb Removed Whitespace errors in DBClient.java
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 100
diff changeset
    86
	}
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    87
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    88
	public String getColumn (int pos) throws SQLException {
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    89
		return resultset.getString (pos);
105
c19e37122deb Removed Whitespace errors in DBClient.java
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 100
diff changeset
    90
	}
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    91
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    92
	public String getColumn (String name) throws SQLException {
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    93
		return resultset.getString (name);
105
c19e37122deb Removed Whitespace errors in DBClient.java
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 100
diff changeset
    94
	}
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    95
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    96
	public List<String> getTables() throws SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    97
		List<String> list = new ArrayList<String>();
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    98
		resultset = metadata.getTables(null, null, "%", null);
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    99
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   100
		while (resultset.next()) {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   101
			list.add(resultset.getString("TABLE_NAME"));
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   102
		}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   103
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   104
		return list;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   105
	}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   106
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   107
	public List<String> getColumns(String table) throws SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   108
		List<String> list = new ArrayList<String>();
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   109
		resultset = metadata.getColumns(null, null, table, null);
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   110
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   111
		while (resultset.next()) {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   112
			list.add(resultset.getString("COLUMN_NAME"));
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   113
		}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   114
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   115
		return list;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   116
	}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   117
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   118
	public Connection getConnection () {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   119
		return connection;
105
c19e37122deb Removed Whitespace errors in DBClient.java
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 100
diff changeset
   120
	}
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   121
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   122
	public String getDbURL () {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   123
		return dbURL;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   124
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   125
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   126
	public String getDriver () {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   127
		return driver;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   128
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   129
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   130
	public String getPassword () {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   131
		return password;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   132
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   133
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   134
	public String getUsername () {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   135
		return username;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   136
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   137
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   138
	public boolean hasNext () throws SQLException {
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   139
		return resultset.next ();
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   140
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   141
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   142
	public void query (String query) throws SQLException {
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   143
		resultset = statement.executeQuery (query);
105
c19e37122deb Removed Whitespace errors in DBClient.java
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 100
diff changeset
   144
	}
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   145
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   146
	/**
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   147
         * returns the number of updated rows
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   148
         */
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   149
	public int update (String update) throws SQLException {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   150
		return statement.executeUpdate (update);
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   151
	}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
   152
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   153
	public void setConnection (Connection connection) {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   154
		this.connection = connection;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   155
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   156
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   157
	public void setDbURL (String dbURL) {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   158
		this.dbURL = dbURL;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   159
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   160
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   161
	public void setDriver (String driver) {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   162
		this.driver = driver;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   163
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   164
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   165
	public void setPassword (String password) {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   166
		this.password = password;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   167
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   168
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   169
	public void setUsername (String username) {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   170
		this.username = username;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   171
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   172
}