日期:2014-05-16  浏览次数:20707 次

java连接oracle 和 mysql 的例子
@Test
public void oravleDemo() throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String url = "jdbc:oracle:thin:@localhost:1521:库名";
    Connection conn = DriverManager.getConnection(url, "username", "password");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select * from SO_T_ENTERPRISE Where SE_I_ID = " );
    while (rs.next()) {
    rs.getString("字段名");
    }
            conn.close();
}


@Test
public void oravleDemo() throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    String url = "jdbc:mysql://localhost:3306/库名";
    Connection conn = DriverManager.getConnection(url, "username", "password");
    Statement stmt = conn.createStatement();
    String sqlparse ="insert into tablr(id) values (1)";
    stmt.execute(sqlparse);
            conn.close();
}