Hi Thomas,
thank you for your reply and once again thank you for this fantastic
database system. For example Postgres has some features like the
restriction of user connections, which can be configured via the .conf
file.
I already figured out, how to determine the number of users (code
below, in case somebody has a similiar problem). I am implementing the
ugly approach and the server as writing a log message in a publicly
accessible table. I am assuming well behaving clients, who first look
into this table and log off, in case there is too much traffic. That's
not ideal, but it works fine.
Bye,
Michael
P.S.: Is it possible to order features on a commercial basis ? The new
features could flow back into the code base and become open sourced as
well.
P.P.S.: The code sample. Properties is a class, that stores the server
settings like the port and so on. It should be easily comprehendable.
//open connection to a tcp server as an admin and retrieve number of
user connections from the memory database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class UserDatabase {
private Connection con;
public UserDatabase(Properties props) {
try {
// System.out.println("connecting to user base");
Class.forName("org.h2.Driver").newInstance();
String url = "jdbc:h2:ssl://localhost:" +
props.getPort()
+ "/mem:management_db_" +
props.getPort()
+ ";ifexists=true";
con = DriverManager.getConnection(url, "sa", "");
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int getUsers() {
int nr;
try {
ResultSet set = con.prepareStatement("SELECT * FROM
SESSIONS")
.executeQuery();
nr = 0;
while (set.next()) {
if (!set.getString(3).equals("SA"))
nr++;
}
return nr;
} catch (SQLException e) {
return 0;
}
}
public void close() {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
UserDatabase user = new UserDatabase(new Properties());
System.out.println(user.getUsers());
}
}
On Oct 16, 1:19 pm, Thomas Mueller <[email protected]>
wrote:
> Hi,
>
> > is there a way to restrict the number of different connections to a
> > tcp server, or to prevent to login with the same username and password
> > from different IPs?
>
> Currently not. What you could do is run a background thread and detect
> if there are too many open sessions (killing new sessions). But it
> would be a relatively ugly workaround.
>
> I will add a feature request for: "Listener or authentication module
> for new connections, or a way to restrict the number of different
> connections to a tcp server, or to prevent to login with the same
> username and password from different IPs. Possibly using the
> DatabaseEventListener API, or a new API.". However, I will not have
> time to implement it in the near future. Patches are welcome of
> course! But I guess first we need to discuss what the best solution
> would be.
>
> Regards,
> Thomas
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.