Hi,
it is possible, that a Textpad-document come from a database
and when i click "File/Save" it stores my document in a database table ?
I want to use TextPad instead of a JTextArea component.
Thanks
Stefan
Textpad and Databases
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Re: Textpad and Databases
Actually, it's not impossible to do that, but you wouldn't do it with File-->Save...
You COULD write a script, (in whatever language you'd prefer, actually, though java'd be my preference,) to take a filename as a parameter and store the contents of the file as a CLOB in a database. Then you could instruct TextPad to run that script under Coinfigure-->Preferences-->Tools-->Add-->DOS Program. For example, here's some code that roughly approximates the procedure:
**************************************************
import java.sql.*;
import java.io.*;
public class DBStore
{
public static void main( String[] args )
{
try
{
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
Connection conn =
DriverManager.getConnection( "jdbc:mysql://localhost/mydb" );
String contents = readFileContents( args[0] );
// I won't explain how to read file contents. It would take too long, and if
// you don't already know, this whole thing will be of no use to you.
int id_number = getIDNumber();
// Identification number for the row. Could just be auto-incrementing.
conn.executeUpdate( "INSERT INTO MYDB.MYTABLE ( IDCOL, CLOBCOL )
VALUES ( " + id_number + ", " + contents " )" );
}
catch( Exception e )
{
System.err.println( e.getMessage() );
}
}
}
You COULD write a script, (in whatever language you'd prefer, actually, though java'd be my preference,) to take a filename as a parameter and store the contents of the file as a CLOB in a database. Then you could instruct TextPad to run that script under Coinfigure-->Preferences-->Tools-->Add-->DOS Program. For example, here's some code that roughly approximates the procedure:
**************************************************
import java.sql.*;
import java.io.*;
public class DBStore
{
public static void main( String[] args )
{
try
{
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
Connection conn =
DriverManager.getConnection( "jdbc:mysql://localhost/mydb" );
String contents = readFileContents( args[0] );
// I won't explain how to read file contents. It would take too long, and if
// you don't already know, this whole thing will be of no use to you.
int id_number = getIDNumber();
// Identification number for the row. Could just be auto-incrementing.
conn.executeUpdate( "INSERT INTO MYDB.MYTABLE ( IDCOL, CLOBCOL )
VALUES ( " + id_number + ", " + contents " )" );
}
catch( Exception e )
{
System.err.println( e.getMessage() );
}
}
}
Re: Textpad and Databases
Oops! Forgot the last part:
Create a new command under Configure-->Preferences-->Tools-->Add-->Program
Set the program to be java.exe.
Set the "Parameters" field to be $File
Leave the "Initial Folder" field as $FileDir
BE WARNED, HOWEVER!
This is NOT a reccommended way to access databases. Nor have I handled closing the connections, or any of the bookkeeping that one must do to make sure that there's no corruption to your database. If you F*** up your database, you've only yourself to blame. Why on earth you'd want to save off files into a database I hae no idea.
Create a new command under Configure-->Preferences-->Tools-->Add-->Program
Set the program to be java.exe.
Set the "Parameters" field to be $File
Leave the "Initial Folder" field as $FileDir
BE WARNED, HOWEVER!
This is NOT a reccommended way to access databases. Nor have I handled closing the connections, or any of the bookkeeping that one must do to make sure that there's no corruption to your database. If you F*** up your database, you've only yourself to blame. Why on earth you'd want to save off files into a database I hae no idea.