日期:2014-05-17  浏览次数:20789 次

连接oracle数据库
写一个简单的登录,数据库只有一张表,我想知道怎么实现与数据库的连接,谁能给个完整的例子,不用任何框架写

------解决方案--------------------
网上这样的例子太多了啊~随便搜一个都可以用的~比如这个(别人的哈我只是随手搜来给你看看)http://blog.csdn.net/linkt/article/details/6406721
别忘了改数据库Url和table名什么的哈~
主要是确保下载并导入了ojdbc的jar包就好,连接语句和其他语言没差太多~
就是这样,喵~
------解决方案--------------------
谷歌搜jdbc数据库连接 代码多的是
------解决方案--------------------
Java code
package zmy.db;

import java.sql.*;

public class DBUtil {

    public static Connection getConnection() {
        Connection conn = null;
        try {
            String driver = "oracle.jdbc.driver.OracleDriver";
            String dbName = "dbname";
            String dbURL = "jdbc:oracle:thin:@localhost:1521:";
            String username = "scott";
            String password = "triger";

            Class.forName(driver).newInstance();
            conn = DriverManager.getConnection(dbURL + dbName, username,
                    password);

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static boolean closeConnection(Connection conn) {
        try {
            conn.close();
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}

------解决方案--------------------
Java code
package zmy.db;

import java.sql.*;

public class DBUtil {

    public static Connection getConnection() {
        Connection conn = null;
        try {
            String driver = "oracle.jdbc.driver.OracleDriver";
            String dbName = "dbname";
            String dbURL = "jdbc:oracle:thin:@localhost:1521:";
            String username = "scott";
            String password = "triger";

            Class.forName(driver).newInstance();
            conn = DriverManager.getConnection(dbURL + dbName, username,
                    password);

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static boolean closeConnection(Connection conn) {
        try {
            conn.close();
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}