|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jcs.util.FileUtil
A class with miscellaneous methods for a client environment:
main: a client-side command-line interpreter to invoke the other methods putString: copies a file to a Java String in the SQL server getString: copies a string from the SQL server to a file putStream: streams a file to a Java String or TEXT column in the SQL server getStream: streams a string or TEXT column from the SQL server to a file file2String: copies a client file to a String variable string2File: copies a String variable to a client fileThese are convenience methods that illustrate file I/O techniques.
Method Summary | |
static java.lang.String |
file2String(java.lang.String fileName)
Copies a client operating system file to a Java String in a Client variable. |
static void |
getStream(java.lang.String outFile,
java.lang.String query,
java.lang.String server)
Streams a TEXT or String column in the SQL server to a client operating system file . |
static void |
getString(java.lang.String outFile,
java.lang.String query,
java.lang.String server)
Copies a Java String from the SQL server to a client operating system file. |
static void |
main(java.lang.String[] args)
Invokes the putString, getString, putStream, and getStream
methods from a client command line. |
static void |
putStream(java.lang.String inFile,
java.lang.String insertStmt,
java.lang.String server)
Streams a client operating system file to a TEXT or String column in the SQL server. |
static void |
putString(java.lang.String inFile,
java.lang.String insertStmt,
java.lang.String server)
Copies a client operating system file to a Java String in the SQL server. |
static void |
string2File(java.lang.String fileName,
java.lang.String source)
Copies a Java String in a Client variable to a client operating system file. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Method Detail |
public static void main(java.lang.String[] args)
putString, getString, putStream, and getStream
methods from a client command line.
Usage:
java jcs.util.FileUtil -S server -A [putString | putStream] -I input-file-name -Q sql-insert-statement java jcs.util.FileUtil -S server -A [getString | getStream] -O output-file-name -Q sql-query
Assume a file named "emps.xml", and the following table:
create table stringtable (id varchar(50), textcol text, stringcol java.lang.String)
Example command lines:
java jcs.util.FileUtil -A putString -I emps.xml \ -S "antibes:4000?user=sa" \ -Q "insert into stringtable (id, stringcol) \ values ('example-1', ?)" java jcs.util.FileUtil -A getString -O emps.getString \ -S "antibes:4000?user=sa" \ -Q "select stringcol \ from stringtable where id='example-1' " java jcs.util.FileUtil -A putStream -I emps.xml \ -S "antibes:4000?user=sa" \ -Q "insert into stringtable (id, textcol) \ values ('example-2', ?)" java jcs.util.FileUtil -A getStream -O emps.getStream \ -S "antibes:4000?user=sa" \ -Q "select textcol from stringtable where id='example-2' "
args
- the String[] containing command line argumentsputString(java.lang.String, java.lang.String, java.lang.String)
,
getString(java.lang.String, java.lang.String, java.lang.String)
,
putStream(java.lang.String, java.lang.String, java.lang.String)
,
getStream(java.lang.String, java.lang.String, java.lang.String)
public static void putString(java.lang.String inFile, java.lang.String insertStmt, java.lang.String server) throws java.lang.Exception
This method can be invoked directly, or from the main
method command line.
Assume a text file named "emps.xml", and the following table:
create table stringtable (id varchar(50), textcol text, stringcol java.lang.String)
Example Java code:
String server = "antibes:4000?user=sa"; String putStringVar = " insert into stringtable (id, stringcol) " +" values ('some-id', ?)"; jcs.util.FileUtil.putString("emps.xml", putStringVar, server);
inFile
- a string that is the name of the file from which to copyinsertStmt
- a string containing an SQL statement that has
a single question-mark parameter.
The datatype of that parameter must be
String
.server
- a string that identifies the server in which to execute
the statement.java.sql
methodsExecSql.connectTo(java.lang.String)
public static void getString(java.lang.String outFile, java.lang.String query, java.lang.String server) throws java.lang.Exception
This method can be invoked directly, or from the main
method command line.
Assume the following table:
create table stringtable (id varchar(50), textcol text, stringcol java.lang.String)
Example Java code:
String server = "antibes:4000?user=sa"; String getStringVar = "select stringcol from stringtable where id='some-id' "; jcs.util.FileUtil.getString2("emps.getString", getStringVar, server);
outFile
- a string that is the name of the file to store intoquery
- a string that contains an SQL query that returns a result set
with one row and one column. The datatype of that column
must be String
.server
- a string that identifies the server in which to execute
the statementjava.sql
methodsExecSql.connectTo(java.lang.String)
public static void putStream(java.lang.String inFile, java.lang.String insertStmt, java.lang.String server) throws java.lang.Exception
This method can be invoked directly, or from the main
method command line.
Assume a file named "emps.xml", and the following table:
create table stringtable (id varchar(50), textcol text, stringcol java.lang.String)
Example Java code:
String server = "antibes:4000?user=sa"; String putStreamVar = "insert into stringtable(id, textcol) " +"values ('putStreamId', ?)"; jcs.util.FileUtil.putStream("emps.xml", putStreamVar, server);
inFile
- a string that is the name of the file from which to copyinsertStmt
- a string that contains an SQL statement that has
a single question-mark parameter.
The datatype of that parameter must be
either TEXT or java.lang.String.server
- identifies the server in which to execute the statementjava.sql
methodsExecSql.connectTo(java.lang.String)
public static void getStream(java.lang.String outFile, java.lang.String query, java.lang.String server) throws java.lang.Exception
This method can be invoked directly, or from the main
method command line.
Assume a file named "emps.xml", and the following table:
create table stringtable (id varchar(50), textcol text, stringcol java.lang.String)
Example Java code:
String getStreamVar = "select textcol from stringtable where id='putStreamId'"; jcs.util.FileUtil.getStream("emps.getStream", getStreamVar, server);
outFile
- a string that is the name of the file to store intoquery
- a string that contains an SQL query that returns a result set
with one row and one column. The datatype of that
column must be either TEXT
or java.lang.String
.server
- a string that identifies the server in which to execute
the statementjava.sql
methodsExecSql.connectTo(java.lang.String)
public static java.lang.String file2String(java.lang.String fileName) throws java.lang.Exception
Example Java code:
String stringFromFile=jcs.util.FileUtil.file2String("my-file.txt");
fileName
- a string that is the name of the file from which to copyjava.io
methodsExecSql.connectTo(java.lang.String)
public static void string2File(java.lang.String fileName, java.lang.String source) throws java.lang.Exception
Example Java code:
jcs.util.FileUtil.file2String("my-file.txt", string-variable);
fileName
- a string that is the name of the file to copy intosource
- the string to copy into the filejava.io
methodsExecSql.connectTo(java.lang.String)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |