ITPub博客

首页 > Linux操作系统 > Linux操作系统 > jian kong

jian kong

原创 Linux操作系统 作者:ganwangge 时间:2009-04-23 22:22:28 0 删除 编辑
  Class.forName("oracle.jdbc.driver.OracleDriver");
         conn = DriverManager.getConnection("jdbc:oracle:thin:@123.15.51.111:1521:ora10g", "ims", "ora123");
         return conn;
 
 
 
  String url = "jdbc:oracle:thin:@" + s + ":1521:" + s1;
         conn = DriverManager.getConnection(url, "system", s2);
         stmt = conn.createStatement();
         rs = stmt.executeQuery("select name from v$database");
 
 
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   Conndb.java
package serv.db;
import java.io.PrintStream;
import java.sql.*;
public class Conndb
{
    private static Connection conn;
    private static Statement stmt;
    private ResultSet rs;
    public Conndb()
    {
    }
    public static synchronized Connection getConn()
       // throws Exception
    {
     try{
         Class.forName("oracle.jdbc.driver.OracleDriver");
         conn = DriverManager.getConnection("jdbc:oracle:thin:@123.15.51.111:1521:ora10g", "ims", "ora123");
         return conn;
        }catch(Exception e){
         System.out.println("Can't Connect DataBase!");
         return null;
        }       
    }
    public Statement getStmtread()
        throws Exception
    {
        conn = getConn();
        stmt = conn.createStatement();
        return stmt;
    }
    public ResultSet getRsQuery(String s)
        throws Exception
    {
        stmt = getStmtread();
        rs = stmt.executeQuery(s);
        return rs;
    }
    public int getRowCount(String s)
        throws Exception
    {
        stmt = getStmtread();
        ResultSet resultset = stmt.executeQuery("select count(*) from " + s);
        resultset.next();
        return resultset.getInt(1);
    }
    public void close()
    {
        try
        {
            if(rs != null)
            {
                rs.close();
                rs = null;
            }
        }
        catch(Exception exception)
        {
            System.out.println(exception.getMessage());
            exception.printStackTrace();
        }
        try
        {
            if(stmt != null)
            {
                stmt.close();
                stmt = null;
            }
        }
        catch(Exception exception1)
        {
            System.out.println(exception1.getMessage());
            exception1.printStackTrace();
        }
        try
        {
            if(conn != null)
            {
                conn.close();
                conn = null;
            }
        }
        catch(Exception exception2)
        {
            System.out.println(exception2.getMessage());
            exception2.printStackTrace();
        }
    }
    public static void main(String args[])
        throws Exception
    {
        Conndb conndb = new Conndb();
        ResultSet rs = conndb.getRsQuery("select * from host1");
        while(rs.next())
         System.out.println(rs.getString(2));
        rs.close();
        conn.close();
    }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   ConnSer.java
package serv.db;
import java.io.*;
import java.sql.*;
import java.util.Date;
import serv.db.Conndb;
import serv.encypt.MyEncypt;

// Referenced classes of package serv.db:
//            Conndb
public class ConnSer
{
    public void newFile(String s)
    {
        try
        {
            String s1 = "D:\\Tomcat\\webapps\\ROOT\\logs\\DBCheck.log";
            File file = new File(s1);
            if(!file.exists())
                file.createNewFile();
            FileWriter filewriter = new FileWriter(file, true);
            PrintWriter printwriter = new PrintWriter(filewriter);
            printwriter.println(s);
            printwriter.close();
        }
        catch(Exception exception)
        {
            System.out.println("Log File is erro!"+exception.getMessage());
        }
    }
    public boolean getRs(String s, String s1, String s2)
        throws Exception
    {
        String s3;
        ResultSet rs = null;
        Statement stmt = null;
        Connection conn = null;
      try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
         String url = "jdbc:oracle:thin:@" + s + ":1521:" + s1;
         conn = DriverManager.getConnection(url, "system", s2);
         stmt = conn.createStatement();
         rs = stmt.executeQuery("select name from v$database");
         if(rs.next())
             s3 = rs.getString(1);
         else
             s3 = "nodb";
         rs.close();
         conn.close();
         if(s3.toUpperCase().equals(s1.toUpperCase()))
             return true;
         else{
             System.out.println("Connect to " + s1 + " failed!");
          return false;
         }
        }catch(Exception e){
         rs.close();
         stmt.close();
         conn.close();
         return false;}
    }
    public static void main(String args[])
        throws Exception
    {
     MyEncypt myencypt = new MyEncypt();
        Conndb conndb = new Conndb();
        ResultSet resultset = conndb.getRsQuery("select ip,sid,pwd from host1 where monitor=1");
        ConnSer connser = new ConnSer();
        boolean flag;
        while(resultset.next())
        {
         System.out.println(resultset.getString("ip"));
            //flag = connser.getRs(resultset.getString("ip"), resultset.getString("sid"), resultset.getString("pwd"));
           // if(!flag)
          //  {
//                Date date = new Date();
//                connser.newFile(date.toString());
//                connser.newFile("Can't connect to DataBase: " + resultset.getString("sid"));
//                connser.newFile("\t\t       IP: 10.200.88.96");
//                connser.newFile("==================================================================");
//                connser.newFile(" ");
      System.out.println(resultset.getString("ip") + " OK");
         //   }
        }
//        if(!connser.getRs("10.200.88.96", "ytsfcdb1", "ssss"))
//        {
//            Date date1 = new Date();
//            connser.newFile(date1.toString());
//            connser.newFile("Can't connect to DataBase: ytsfcdb1");
//            connser.newFile("\t\t       IP: 10.200.88.96");
//            connser.newFile("==================================================================");
//            connser.newFile(" ");
//        }
  resultset.close();
  conndb.close();
    }
}
 
 
 
 
 
 
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11366721/viewspace-591667/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: CREATE TABLESPACE
请登录后发表评论 登录
全部评论

注册时间:2009-03-30

  • 博文量
    22
  • 访问量
    5590