mysql 结果集java_JAVA调用ORACLE和MYSQL返回结果集

ef6b33f0ac6f0ae3adfd93af3940aa32.png

import java.sql.*;

import java.io.*;

//import oracle.jdbc.driver.*;

public class JDBCDemo {

//private String driver = "oracle.jdbc.driver.OracleDriver";

//private String url = "jdbc:oracle:thin:@192.168.1.213:1521:luke";

private String driver = "com.mysql.jdbc.Driver";

private String url = "jdbc:mysql://192.168.1.213:3306/luke";

private Connection conn = null;

public JDBCDemo()

throws ClassNotFoundException, SQLException {

try {

Class.forName(driver);

conn = DriverManager.getConnection(url, "luke", "luke");

}

catch (SQLException ex) {

System.out.println("Failed to establish a connection to: " + url);

throw ex;

}

}

private void execute(int n)

throws SQLException {

String query = "{call proc_shop_num(?,?,?) }";

System.out.println("Query: " + query + "n");

CallableStatement stmt = conn.prepareCall(query);

stmt.setInt(1,n);

stmt.setInt(2,3);

//stmt.registerOutParameter(1, OracleTypes.CURSOR);

//stmt.execute();

ResultSet rs = stmt.executeQuery();

//ResultSet rs = (ResultSet)stmt.getObject(1);

System.out.println(stmt.getInt(1));

while (rs.next()) {

System.out.println(rs.getString(2));

}

rs.close();

stmt.close();

}

private void cleanup() throws SQLException {

if (conn != null)

conn.close();

}

public static void main(String[] args) throws Exception {

JDBCDemo t = new JDBCDemo();

try {

t.execute(Integer.parseInt(args[0]));

t.cleanup();

}

catch (SQLException ex) {

System.out.println("Demo failed: " + ex.getMessage());

}

}

}

2829f2ca24f0d0090cbba57f30759f23.png

JAVA调用ORACLE和MYSQL返回结果集.doc

下载Word文档到电脑,方便收藏和打印[全文共832字]

编辑推荐:

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

下载Word文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值