Device1.bat
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name=request.getParameter("name");
String commun=request.getParameter("commun");
String password=request.getParameter("password");
Connection conn = null;
Statement statement = null;
try{
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/community");
conn = ds.getConnection();
statement = conn.createStatement();
String sql = "select memberragas from windowragas where memberragas='"+name+"' and liquid_key='"+commun+"' and chabhiragas='"+password+"'";
ResultSet rs =statement.executeQuery(sql);
if(rs.next()){
System.out.println("welcome "+name+"");
HttpSession session=request.getSession();
session.setAttribute("name", name);
session.setAttribute("commun", commun);
RequestDispatcher rd = request.getRequestDispatcher("/homey");
rd.forward(request, response);
}else{
System.out.println("either ur username or password or community was wrong");
response.sendRedirect(request.getContextPath());
}
}
catch (NamingException ex) {
System.err.println(ex);
} catch (SQLException ex) {
System.err.println(ex);
}finally {
try {
if (statement != null) statement.close();
if (conn != null) conn.close(); // return to pool
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
Device2.bat
@echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
我一次运行device1.bat和device2.bat。 Device1.bat运行正常。但是device2.bat抛出进程无法访问该文件,因为正在被另一个进程使用。请帮助我解决这个问题。
答案 0 :(得分:0)
您可以为device2制作config.properties的临时副本,以便稍后使用和删除。 设备1:
@echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
::make a temporary copy of config.properties
copy config.properties config2.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
DEVICE2.bat:
@echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
::changed config.properties to config2.properties
SET FILE=config2.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
::delete the temporary config2.properties
del /f /q config2.properties
:end
希望有所帮助!