jian kong

  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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/11366721/viewspace-591667/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值