我在 Oracle 中为我的项目使用了一个名为 LogMiner 的工具。我在 Windows 7 32 位机器上使用 Oracle 10g。
为了启动日志挖掘工具,我登录sqlplus
并执行以下查询:
//Query to create flat file
alter system set utl_file_dir='C:\oracle\product\10.2.0\logminer_dir' scope=spfile;
shutdown immediate
startup
show parameter utl_file_dir
SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;
alter system switch logfile;
这个 PL/SQL 查询使用 sqlplus 运行良好,但现在我想在 Java 中使用 jdbc 运行同样的查询
我为它编写了以下代码,如下所示:
package src;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
public class LogMiner extends javax.swing.JFrame {
private JLabel jLabel1;
private JButton jButton1;
private JButton jButton4;
private JButton jButton3;
private JButton jButton2;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
LogMiner inst = new LogMiner();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public LogMiner() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("LogMiner Tool");
jLabel1.setBounds(236, 18, 97, 21);
}
{
jButton1 = new JButton();
getContentPane().add(jButton1);
jButton1.setText("Create the flat file");
jButton1.setBounds(212, 71, 133, 28);
}
pack();
setSize(600, 400);
} catch (Exception e) {
e.printStackTrace();
}
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
//write query statement
try
{
// load oracle driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// connect using Thin driver
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:test","system","oracle");
System.out.println("Connected Successfully To Oracle");
//getting errors in the following line...need help here
String sql="alter system set
utl_file_dir='C:\oracle\product\10.2.0\logminer_dir'scope=spfile;"
+"shutdown immediate"+
"startup"+
"show parameter utl_file_dir"+
"SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE"+
"alter system switch logfile";
Statement statement = con.createStatement();
ResultSet resultset = statement.executeUpdate(sql);
resultset.next();
String s = resultset.getString(1);
System.out.println(s);
statement.close();
con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
});
}
}
我应该如何在 Java 中编写相同的查询才能正确执行?有人可以告诉我吗?