Internship work, completed the task entrusted to the leadership, the collected data into the database, the code snippet is as follows:
Static Connection getconnection ()
throws SQLException, IOException, classnotfoundexception
{
Properties props = new Properties ();
FileInputStream in = new FileInputStream ("Company.ini");
Props.load (in);
In.close ();
String driver=props.getproperty ("Driver");
String url = props.getproperty ("url");
String user = Props.getproperty ("user");
String pass = props.getproperty ("pass");
Load Database driver
class.forname (driver);
Get the database connection return
drivermanager.getconnection (URL, user, pass);
}
This is the code that JDBC gets the database connection, the configuration information of the database is written in the Company.ini file.
The following is the code that reads the data from the specified file and inserts it into the specified table in the database.
Try
{
BufferedReader br=new bufferedreader (New FileReader ("Data.txt"));
String Line=null;
while ((Line=br.readline ())!=null)
{
String date=new java.text.SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"). Format (new Date ());
String sql= "INSERT into keyword_garbage values (null, ' +line+" ', ' "+insert.keywordencode (line) +" ', 0,0, ' "+date+", NULL) ";
Try
{
stmt.executeupdate (SQL);
}
catch (SQLException E2)
{
e2.printstacktrace ();
}}} catch (filenotfoundexception E2)
{
e2.printstacktrace ();
}
catch (IOException E2)
{
e2.printstacktrace ();
}
Because there is no special requirement for exception capture, I only meet the grammatical requirements. We can make further changes according to the actual situation.