|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jcs.util.ExecSql
A class with miscellaneous static methods to execute SQL statements and scripts.
connectTo(server) - Return a connection to the given server.
Specify an empty server
when you invoke
this method in the server.
statement(sql, server) - Get a connection and execute the given SQL statement.
query(sql, server) - Get a connection, execute the given SQL query, and return
the ResultSet.
querySingleString(sql, server) - Get a connection, execute the given query,
which must return a single column/row that is a string, and return that string.
querySingleInt(sql, server) - Get a connection, execute the given query,
which must return a single column/row that is an int, and return that int.
Method Summary | |
static java.sql.Connection |
connectTo(java.lang.String server)
Connects to the given SQL server. |
static java.sql.ResultSet |
query(java.lang.String query,
java.lang.String server)
Connects to the given server, and executes the given SQL query. |
static int |
querySingleInt(java.lang.String query,
java.lang.String server)
Connects to the given server, executes the given single-valued SQL query, and returns that single (int) value. |
static java.lang.String |
querySingleString(java.lang.String query,
java.lang.String server)
Connects to the given server, executes the given single-valued SQL query, and returns that single (String) value. |
static void |
statement(java.lang.String sql,
java.lang.String server)
Connects to the given server, and executes the given SQL statement. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Method Detail |
public static java.sql.Connection connectTo(java.lang.String server) throws java.lang.Exception
This method is intended for routines that will run in either a client or server environment.
server
parameter that is null, empty
or blank, or is jdbc:default:connection
indicates
a server-side call,
using the native JDBC driver.
server
parameter that is not empty and not
jdbc:default:connection
should be a valid url
for a client-side connect,
using the jConnect JDBC driver. This parameter must include the
server-name, port-number, user-name, and (optional) password.
sFor example:
antibes:4000?user=jsmith&password=wxyz antibes:4000?user=saIn the second example, the password is omitted and is empty by default.
server
- a string that identifies the server. See above.java.io, java.sql, or java.util
public static void statement(java.lang.String sql, java.lang.String server) throws java.lang.Exception
Example Java code:
ExecSql.statement("delete from emps", ""); String stmt = "set quoted_identifier on " + "insert into emps('emp id', name) " + + "values('12345', 'John Doe')"; ExecSql.statement(stmt, "some-server:1000?user=sa");
sql
- a string with the SQL statement to be executed.
This statement must have no question-mark parameters,
and must return no result set.server
- a string that identifies the server in which to execute
the statement.java.io, java.sql, or java.util
connectTo(java.lang.String)
public static java.sql.ResultSet query(java.lang.String query, java.lang.String server) throws java.lang.Exception
Example Java code:
java.sql.ResultSet rs = ExecSql.query("select * from systypes", "");
sql
- a string with the SQL statement to be executed.
This statement must have no question-mark parameters,
and must return a result set.server
- a string that identifies the server in which to execute
the statement.java.io, java.sql, or java.util
connectTo(java.lang.String)
public static java.lang.String querySingleString(java.lang.String query, java.lang.String server) throws java.lang.Exception
This is a convenience method for non-parametrized queries that return a single row with a single string column.
Example Java code:
String s = ExecSql.querySingleString("select max(name) from systypes", "antibes:4000?user=sa");
sql
- a string with the SQL statement to be executed.
This statement must have no question-mark parameters,
and must return a result set with a single row and
a single column that is a character string or String.server
- a string that identifies the server in which to execute
the statement.java.io, java.sql, or java.util
connectTo(java.lang.String)
public static int querySingleInt(java.lang.String query, java.lang.String server) throws java.lang.Exception
This is a convenience method for non-parametrized queries that return a single row with a single column.
Example Java code:
String s = query("select count(*) from systypes", "antibes:4000?user=sa");
sql
- a string with the SQL statement to be executed.
This statement must have no question-mark parameters,
and must return a result set with a single row and
a single column that is an integer.server
- a string that identifies the server in which to execute
the statement.java.io, java.sql, or java.util
connectTo(java.lang.String)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |