Subject | Firebird and multiple threads |
---|---|
Author | fabiano_bonin |
Post date | 2006-05-29T01:03:49Z |
Hi,
I'm an old FB user, but i'm new to Java and i'm testing JayBird for
the first time.
Is it possible to open 1 connection to a database and run many
statements simultaneously using threads?
I'm trying this, but it's not working (sorry if i'm doing something dumb)
package jdbc;
import java.sql.*;
public class ThreadResultSet implements Runnable {
private Statement stmt;
private ResultSet rs;
private String sql;
private Thread thr;
public ThreadResultSet(Connection conn, String sql) throws Exception {
stmt = conn.createStatement();
this.sql = sql;
thr = new Thread(this);
thr.start();
}
public void run() {
try {
rs = stmt.executeQuery(sql);
rs.next();
System.out.println(thr.getName() + " - " + rs.getString(1));
stmt.close();
} catch (SQLException E) {
System.out.println(thr.getName() + " - " + E.toString());
}
}
}
Regards,
Fabiano.
I'm an old FB user, but i'm new to Java and i'm testing JayBird for
the first time.
Is it possible to open 1 connection to a database and run many
statements simultaneously using threads?
I'm trying this, but it's not working (sorry if i'm doing something dumb)
package jdbc;
import java.sql.*;
public class ThreadResultSet implements Runnable {
private Statement stmt;
private ResultSet rs;
private String sql;
private Thread thr;
public ThreadResultSet(Connection conn, String sql) throws Exception {
stmt = conn.createStatement();
this.sql = sql;
thr = new Thread(this);
thr.start();
}
public void run() {
try {
rs = stmt.executeQuery(sql);
rs.next();
System.out.println(thr.getName() + " - " + rs.getString(1));
stmt.close();
} catch (SQLException E) {
System.out.println(thr.getName() + " - " + E.toString());
}
}
}
Regards,
Fabiano.