/**********************************************************************/
/* labposition.java */
/* Sample Java program for "DB2 UDB PROGRAMMING USING JAVA" */
/* ( CG11 ) */
/* */
/* Learn how to establish in position in a ResultSet */
/* */
/* */
/* Last update = 01/31/2000 */
/* */
/**********************************************************************/
/* Notes: */
/* */
/* This program is intended to be completed with the lab guide */
/* as a reference. The lab guide is the set of instructions that */
/* should be followed. The comments in this program are intended */
/* to clarify statements made in the lab guide. */
/**********************************************************************/
/**********************************************************************/
/* Import Java Classes */
/**********************************************************************/
import java.sql.*;
import sqlj.runtime.*;
import sqlj.runtime.ref.*;
import java.io.*;
import java.util.*;
import java.math.*;
/**********************************************************************/
/* Class definition */
/**********************************************************************/
public class labposition
{
/**********************************************************************/
/* Register the class with the db2 Driver */
/**********************************************************************/
static
{ try
{ Class.forName ("COM.ibm.db2.jdbc.app.DB2Driver");
}
catch (Exception e)
{ System.out.println ("\n Error loading DB2 Driver...\n");
System.out.println (e);
System.exit(1);
}
}
/**********************************************************************/
/* Main routine */
/**********************************************************************/
public static void main( String args[]) throws Exception
{
/**********************************************************************/
/* Define variable declarations for the variable which will be used */
/* to pass data to and from the stored procedure: */
/* A character string for passing the department in. */
/* A double for returning the median salary. */
/* An integer for returning the number of employees. */
/**********************************************************************/
String name = "";
java.lang.String deptno = "";
short id = 0;
String salary = "";
String job = "";
short NumEmp = 0;
BufferedReader in = new BufferedReader( new InputStreamReader (System.in));
String s;
/***********************************************************************/
/* Header line */
/***********************************************************************/
String intext =
"\n NAME JOB SALARY\n";
String indash =
"-------- -------- --------------\n";
String blanks = " ";
String outline = "";
/* Establish connection and set default context */
System.out.println("Connect statement follows:");
/********************* ???????????????? ************************/
/* ( 1 ) Code the connect statement to the database SAMPLE */
/* use the Connection object named sample. */
/***************************************************************/
Connection sample = DriverManager.getConnection("jdbc:db2:sample","udba","udba");
System.out.println("Connect completed");
sample.setAutoCommit(false);
/* Issue Select statement */
System.out.println("Statement stmt follows");
try
{
/************************ ?????????????????????? ***********************/
/* Execute the statement SELECT * FROM STAFF */
/* */
/* Print out the results by filling in the appropriate variable */
/* names in each of the following println invocations. */
/***********************************************************************/
/************************** ???????????????????? ***********************/
/* ( 2 ) Define the ResultSet object named rs. */
/* Initialize the rs object to null. */
/***********************************************************************/
ResultSet rs = null;
/************************** ???????????????????? ***********************/
/* ( 3 ) Define the variable sql which contain the select statement */
/* SELECT NAME, JOB, SALARY FROM STAFF */
/***********************************************************************/
String sql = "select NAME, JOB, SALARY from staff ";
/************************** ???????????????????? ***********************/
/* ( 4 ) Instantiate the PreparedStatement object stmt. */
/* Make the cursor allow for scrollable backward and forward */
/***********************************************************************/
PreparedStatement stmt = sample.prepareStatement(sql,
rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_READ_ONLY);
System.out.println( intext );
System.out.println( indash );
rs = stmt.executeQuery( );
/************************** ???????????????????? ***********************/
/* ( 5 ) Scrollforward through the result set. */
/* */
/***********************************************************************/
rs.next();
name = rs.getString(1);
job = rs.getString(2);
salary = rs.getString(3);
outline = (name + blanks.substring(0, 10 - name.length())) +
(job + blanks.substring(0, 10 - job.length())) +
(salary + blanks.substring(0, 12 - salary.length()));
System.out.println("\n" + outline);
/************************** ???????????????????? ***********************/
/* ( 6 ) Retrieve the last row of the result set */
/* */
/***********************************************************************/
rs.last();
name = rs.getString(1);
job = rs.getString(2);
salary = rs.getString(3);
outline = (name + blanks.substring(0, 10 - name.length())) +
(job + blanks.substring(0, 10 - job.length())) +
(salary + blanks.substring(0, 12 - salary.length()));
System.out.println("\n" + outline);
/************************** ???????????????????? ***********************/
/* ( 7 )
数据库系统原理PPT.7z
版权申诉
92 浏览量
2022-07-06
07:31:25
上传
评论
收藏 19.69MB 7Z 举报
BryanDing
- 粉丝: 297
- 资源: 5585
最新资源
- 关于数据分析工具的问题 (Excel、PowerBI-Tableau、R-Python)-教程案例分享.zip
- jqueryUI管理后台+WeiXinApp微信小程序+uni例子内容 参数例子,学习用
- 基于聚类分析分批训练的BP神经网络回归分析
- 计算机大类学生课程实验心得、案例-基于Python 的图像处理实验.zip
- CocosDashboard-v2.1.3-win-042311.exe
- vue3-admin-master-后台管理平台模板.zip
- 基于yolov5和deepsort算法的车辆检测项目源码+数据集(高分项目).zip
- 使用Python的requests库和BeautifulSoup库进行网页爬取的示例案例
- 蓝色个人主页接单HTML源码.zip
- 基于YOLOv5+Deepsort实现车辆行人追踪和计数(完整源码+说明文档+数据).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0