⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbconnection.java

📁 一个不错的留言系统
💻 JAVA
字号:
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2002-6-14 16:28:57
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   DBConnection.java

package com.shlt.dbconnection;

import java.io.*;
import java.sql.*;
import java.util.Properties;

public class DBConnection
{

    public DBConnection()
    {
        File file = new File("shltDb.properties");
        String s = file.getAbsolutePath().replace('\\', '/');
        Properties properties = new Properties();
        try
        {
            FileInputStream fileinputstream = new FileInputStream(s);
            properties.load(fileinputstream);
            if(fileinputstream != null)
                fileinputstream.close();
        }
        catch(IOException ioexception)
        {
            System.out.println("Open config file failure.");
        }
        db_type = properties.getProperty("db_type");
        user = properties.getProperty("user");
        password = properties.getProperty("password");
        byte byte0 = 2;
        if(db_type.equals("oracle"))
            byte0 = 1;
        switch(byte0)
        {
        default:
            break;

        case 1: // '\001'
            db_ip = properties.getProperty("db_ip");
            db_port = properties.getProperty("db_port");
            db_uid = properties.getProperty("db_uid");
            try
            {
                Class.forName("oracle.jdbc.driver.OracleDriver");
            }
            catch(ClassNotFoundException classnotfoundexception)
            {
                System.out.println("Could not load the driver.");
                classnotfoundexception.printStackTrace();
            }
            String s1 = user + "/" + password + "@" + db_ip + ":" + db_port + ":" + db_uid;
            try
            {
                db_conn = DriverManager.getConnection("jdbc:oracle:thin:" + s1);
            }
            catch(SQLException sqlexception)
            {
                System.out.println("Creat connection error.");
                sqlexception.printStackTrace();
            }
            break;

        case 2: // '\002'
            db_driver = properties.getProperty("db_driver");
            db_url = properties.getProperty("db_dsn");
            try
            {
                Class.forName(db_driver);
            }
            catch(ClassNotFoundException classnotfoundexception1)
            {
                classnotfoundexception1.printStackTrace();
            }
            try
            {
                db_conn = DriverManager.getConnection(db_url, user, password);
            }
            catch(SQLException sqlexception1)
            {
                sqlexception1.printStackTrace();
            }
            break;
        }
    }

    public void setuser(String s)
    {
        user = s;
    }

    public void setpassword(String s)
    {
        password = s;
    }

    public String getuser()
    {
        return user;
    }

    public String getpassword()
    {
        return password;
    }

    public String getdbtype()
    {
        return db_type;
    }

    public int getrecordcount()
    {
        return record_count;
    }

    public int getfieldcount()
    {
        return field_count;
    }

    public ResultSet executeQuery(String s)
        throws SQLException
    {
        db_stmt = db_conn.createStatement();
        int i = s.indexOf("from");
        if(i < 0)
            i = s.indexOf("FROM");
        String s1 = s.substring(i);
        s1 = "select count(*) " + s1;
        db_rset = db_stmt.executeQuery(s1);
        if(db_rset.next())
            record_count = db_rset.getInt(1);
        db_rset = db_stmt.executeQuery(s);
        ResultSetMetaData resultsetmetadata = db_rset.getMetaData();
        field_count = resultsetmetadata.getColumnCount();
        return db_rset;
    }

    public int executeUpdate(String s)
        throws SQLException
    {
        db_stmt = db_conn.createStatement();
        return db_stmt.executeUpdate(s);
    }

    public String getColumnName(int i)
        throws SQLException
    {
        ResultSetMetaData resultsetmetadata = db_rset.getMetaData();
        return resultsetmetadata.getColumnName(i);
    }

    public String getData(int i)
        throws SQLException
    {
        return db_rset.getString(i).trim();
    }

    public String getData(String s)
        throws SQLException
    {
        return db_rset.getString(s).trim();
    }

    public boolean next()
        throws SQLException
    {
        return db_rset.next();
    }

    public void close()
        throws SQLException
    {
        if(db_conn != null)
            db_conn.close();
        if(db_stmt != null)
            db_stmt.close();
        if(db_rset != null)
            db_rset.close();
    }

    public Connection getConnection()
    {
        return db_conn;
    }

    public CallableStatement spCall(String s)
        throws Exception
    {
        return db_conn.prepareCall(s);
    }

    public String db_ip;
    public String db_port;
    public String db_uid;
    public String user;
    public String password;
    public String db_driver;
    public String db_url;
    public String db_type;
    public String Sqlstring;
    public Connection db_conn;
    public Statement db_stmt;
    public ResultSet db_rset;
    public int record_count;
    public int field_count;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -