How to Get connection in spring
Javax. servlet. servletcontext = request. getsession (). getservletcontext (); Org. springframework. web. context. webapplicationcontext = org. springframework. web. context. support. webapplicationcontextutils. getrequiredwebapplicationcontext (servletcontext );
Datasource = (datasource) webapplicationcontext. getbean ("datasource ");
Connection conn = NULL;
Resultset rs = NULL;
Statement stmt = NULL;
String sqlstring = "";
// Define the query statement inputstream in = NULL; // define the input stream
Int Len = 10*1024*1024; // defines the length of the character array
Try {
Sqlstring = "select d402_02 from d402 where d402_01 = '" + request. getparameter ("ID") + "'";
Conn = datasource. getconnection ();
Stmt = conn. createstatement ();
Rs = stmt.exe cutequery (sqlstring );
} Catch (exception e ){
System. Out. println ("Photo-Database Operation No.:" + request. getparameter ("ID "));
}