1. Insert a local file into the database, the database field is saved with text
public static void Main (string[] args) {
Propkit.use ("Pro.txt");
Druidplugin Druid = new Druidplugin (Propkit.get ("Jdbcurl"), Propkit.get ("user"), Propkit.get ("password"));
Druid.start ();
Activerecordplugin arp = new Activerecordplugin (druid);
Arp.start ();
Connection conn = null;
PreparedStatement st = null;
try {
Conn= dbkit.getconfig (). getconnection ();
String sql = "INSERT into test (name) VALUES (?)";
st = conn.preparestatement (SQL);
String Path = "1.text";
File File = new file (path);
St.setcharacterstream (1, new FileReader (file), file.length ());
int num = St.executeupdate (); Perform an INSERT into the database
if (num > 0) {
System.out.println ("Insert Success");
}
} catch (Exception e) {
E.printstacktrace ();
}
}
2. Read the content from the database and save it as text to the local
public static void Main (string[] args) {
Propkit.use ("Pro.txt");
Druidplugin Druid = new Druidplugin (Propkit.get ("Jdbcurl"), Propkit.get ("user"), Propkit.get ("password"));
Druid.start ();
Activerecordplugin arp = new Activerecordplugin (druid);
Arp.start ();
Connection conn = null;
PreparedStatement st = null;
ResultSet Rs=null;
try {
Conn= dbkit.getconfig (). getconnection ();
String sql = "SELECT name from Test where id=?";
st = conn.preparestatement (SQL);
St.setint (1, 1);
rs = St.executequery (); Execute SQL statement
if (Rs.next ()) {
Reader reader = rs.getcharacterstream ("name"); Gets the item that the field is not name, which is the 1.txt file we just saved to the database
Char buffer[] = new char[1024];
int len = 0;
FileWriter out = new FileWriter ("D:\\1.txt"); Write it down to the D drive.
while (len = reader.read (buffer)) > 0) {
Out.write (buffer, 0, Len);
}
Out.close ();
Reader.close ();
}
} catch (Exception e) {
E.printstacktrace ();
}
}
MySQL Insert text document and read