在ORACLE中JAVA代码里的锁起作用吗,怎么我用的好像不起作用
create or replace and compile java source named notnew as
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
import java.util.concurrent.locks.*;
public class RedirectOutput
{
public synchronized static void redirect(String message)
throws Exception
{
synchronized(RedirectOutput.class)
{
PrintStream ps=null;
// Connect to Oracle using JDBC driver
//Connection conn = DriverManager.getConnection("jdbc:default:connection:");
// Build SQL statement
//String sql = "DROP " + object_type + " " + object_name;
try
{
ps=new PrintStream(new FileOutputStream(new File("d:\\message.txt"),true));
System.setOut(ps);
ps.println(message);
//Statement stmt = conn.createStatement();
//stmt.executeUpdate(sql);
//stmt.close();
}
catch (Exception e)
{
ps.println(e.getMessage());
}
finally
{
ps.close();
}
}
}
public synchronized static void justDoIt(String tbn)
{
synchronized(RedirectOutput.class)
{
PrintStream ps=null;
String label ="";
String value ="";
// Connect to Oracle using JDBC driver
// Build SQL statement
String sql = "commit";//String sql="select * from "+tbn+" where rowid=(select max(rowid) from "+tbn+" )";
String result="just for fun";
try
{
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
ps=new PrintStream(new FileOutputStream(new File("d:\\message.txt"),true));
System.setOut(ps);
//ps.println(sql);
//ps.println(message);
Statement stmt = conn.createStatement();
//ps.println("*********************************************************");
//stmt.executeQuery(sql);
//ps.println("****************************3***********2**********1********");
sql = "Select * from "+ tbn +" VERSIONS BETWEEN timestamp MINVALUE AND MAXVALUE where versions_starttime=(select max(versions_starttime) from "+tbn+" VERSIONS BETWEEN timestamp MINVALUE AND MAXVALUE)";
ResultSet rset=stmt.executeQuery(sql);
ResultSetMetaData meta = rset.getMetaData();
int cols=meta.getColumnCount();
//ps.println(cols+"****************************************************");
ps.print("*****开始打印LABEL*****");
for(int m=1;m<=cols;m++)
{
label=meta.getColumnLabel(m);
while(label.length()<=17)
{
label+=" ";
}
ps.print(label);
}
ps.println(" ");
//while (rset.next())
if(rset.next())
{
ps.print("*****开始打印VALUE*****");
for(int m=1;m<=cols;m++)
{
value = rset.getString(m);
if(value!=null)
{
while(value.length()<=10)
{
value+=" ";
}
ps.print(value.substring(0,10)+" ");
}
else
{
ps.print(" ");
}
}
}
rset.close();
stmt.close();
ps.println(" ");
ps.println("-------------------------------------------------------------------------------------------------------------------------------------------");
ps.println(" ");
}
catch (Exception e)
{
ps.println(e.getMessage());
}
finally
{
ps.close();
}
}
}
}那个justDoIt方法居然能同时被二个JOB访问。。请问问题出在哪
create or replace and compile java source named notnew as
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
import java.util.concurrent.locks.*;
public class RedirectOutput
{
public synchronized static void redirect(String message)
throws Exception
{
synchronized(RedirectOutput.class)
{
PrintStream ps=null;
// Connect to Oracle using JDBC driver
//Connection conn = DriverManager.getConnection("jdbc:default:connection:");
// Build SQL statement
//String sql = "DROP " + object_type + " " + object_name;
try
{
ps=new PrintStream(new FileOutputStream(new File("d:\\message.txt"),true));
System.setOut(ps);
ps.println(message);
//Statement stmt = conn.createStatement();
//stmt.executeUpdate(sql);
//stmt.close();
}
catch (Exception e)
{
ps.println(e.getMessage());
}
finally
{
ps.close();
}
}
}
public synchronized static void justDoIt(String tbn)
{
synchronized(RedirectOutput.class)
{
PrintStream ps=null;
String label ="";
String value ="";
// Connect to Oracle using JDBC driver
// Build SQL statement
String sql = "commit";//String sql="select * from "+tbn+" where rowid=(select max(rowid) from "+tbn+" )";
String result="just for fun";
try
{
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
ps=new PrintStream(new FileOutputStream(new File("d:\\message.txt"),true));
System.setOut(ps);
//ps.println(sql);
//ps.println(message);
Statement stmt = conn.createStatement();
//ps.println("*********************************************************");
//stmt.executeQuery(sql);
//ps.println("****************************3***********2**********1********");
sql = "Select * from "+ tbn +" VERSIONS BETWEEN timestamp MINVALUE AND MAXVALUE where versions_starttime=(select max(versions_starttime) from "+tbn+" VERSIONS BETWEEN timestamp MINVALUE AND MAXVALUE)";
ResultSet rset=stmt.executeQuery(sql);
ResultSetMetaData meta = rset.getMetaData();
int cols=meta.getColumnCount();
//ps.println(cols+"****************************************************");
ps.print("*****开始打印LABEL*****");
for(int m=1;m<=cols;m++)
{
label=meta.getColumnLabel(m);
while(label.length()<=17)
{
label+=" ";
}
ps.print(label);
}
ps.println(" ");
//while (rset.next())
if(rset.next())
{
ps.print("*****开始打印VALUE*****");
for(int m=1;m<=cols;m++)
{
value = rset.getString(m);
if(value!=null)
{
while(value.length()<=10)
{
value+=" ";
}
ps.print(value.substring(0,10)+" ");
}
else
{
ps.print(" ");
}
}
}
rset.close();
stmt.close();
ps.println(" ");
ps.println("-------------------------------------------------------------------------------------------------------------------------------------------");
ps.println(" ");
}
catch (Exception e)
{
ps.println(e.getMessage());
}
finally
{
ps.close();
}
}
}
}那个justDoIt方法居然能同时被二个JOB访问。。请问问题出在哪
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货