嵌入式SQL编程实验报告
嵌入式编程基础实训报告

一、实训目的本次实训旨在使学生了解嵌入式系统的基本概念、组成及工作原理,掌握嵌入式编程的基本方法和技巧,提高学生实际动手能力和团队协作能力。
二、实训内容1. 嵌入式系统基础知识(1)嵌入式系统定义:嵌入式系统是指嵌入在某种设备中,为特定应用而设计的计算机系统。
它具有体积小、功耗低、可靠性高、实时性强等特点。
(2)嵌入式系统组成:嵌入式系统主要由硬件和软件两部分组成。
硬件包括处理器、存储器、输入/输出设备等;软件包括操作系统、驱动程序、应用程序等。
(3)嵌入式系统工作原理:嵌入式系统通过处理器执行程序,实现对硬件资源的控制,完成特定功能。
2. 嵌入式编程基础(1)C语言编程:C语言是嵌入式系统开发中常用的编程语言,具有可移植性强、执行效率高、易于理解等特点。
(2)嵌入式操作系统:嵌入式操作系统是嵌入式系统中的核心软件,负责管理硬件资源、调度任务、提供通信接口等。
常见的嵌入式操作系统有Linux、Windows CE、VxWorks等。
(3)驱动程序开发:驱动程序是嵌入式系统与硬件设备之间的接口,负责实现硬件设备的初始化、配置、控制等功能。
3. 实训项目本次实训项目为基于STM32的嵌入式系统开发,主要包括以下步骤:(1)搭建开发环境:下载并安装STM32CubeIDE、STM32CubeMX、ST-LINK等开发工具。
(2)创建项目:在STM32CubeMX中配置硬件资源,如时钟、GPIO、USART等。
(3)编写代码:使用C语言编写应用程序,实现LED控制、按键扫描、串口通信等功能。
(4)编译、下载与调试:编译项目生成hex文件,通过ST-LINK下载到STM32开发板,使用调试工具进行调试。
(5)测试与优化:测试程序功能,对程序进行优化,提高系统性能。
三、实训过程1. 学习嵌入式系统基础知识,了解嵌入式系统的组成、工作原理及编程方法。
2. 搭建开发环境,学习STM32CubeIDE、STM32CubeMX、ST-LINK等开发工具的使用。
实验4嵌入式SQL和ODBC的使用

实验4 嵌入式SQL和ODBC的使用实验人:田超(31311039)黄伟(31311064)实验目的1.熟悉ODBC的配置和使用2.熟悉嵌入式SQL编程3.巩固SQL的知识实验平台1.OS:WindowsXP2.DBMS:SQLServer2000piler:Visual C++ 6.0预备知识1)嵌入式SQL编程:嵌入式SQL由SQL语句和C/C++代码组成。
其中SQL语句由预处理器翻译成C或C++的源代码。
对预处理后的源代码进行编译、连接生成可执行程序后方可运行。
●SQL预处理器SQLServer的预处理程序是nsqlprep.exe。
其常用的语法格式如下:nsqlprep 程序文档名⏹nsqlprep详细的语法格式以及参数意义,请看联机帮助。
经查阅联机帮助,nsqlprep的语法格式如下:nsqlprep program_file_name [/SQLACCESS | /NOSQLACCESS][/FLAGGER {ENTRY | NONE}] [/DB [server_name.]database_name/PASS {login[.password] | $INTEGRATED}] [/BIND file_name][/MSG file_name] [/NOLOGO] [/PLAN name] [/NOLINES][/user_defined_option]⏹要求程序文档名的后缀为.sqc,可以省略。
⏹预编译后得到的文档,与程序文档同名,后缀为.c;放在与程序文档名同一个路径下nsqlprep.exe在SQLServer的安装目录的MSSQL\Binn下。
在本机中SQLServer的安装目录是C:\Program Files\Microsoft SQL Server,nsqlprep.exe在C:\Program Files\Microsoft SQL Server\MSSQL\Binn。
嵌入式sql

实验四:访问数据库一、实验目的利用ODBC和任意一种高级语言,编写一段访问数据库的程序。
要求该程序可以实现查询,插入、删除和更新功能。
二、实验代码这次试验是使用C#编写的,界面与代码如下:string connString = "Data Source=(local);Initial Catalog=Factory;Integrated Security=True;";SqlConnection connection = new SqlConnection(connString);connection.Open();string SCommand = "select * from 工作人员表;SqlDataAdapter adapter = new SqlDataAdapter(SCommand, connection);DataSet DSet = new DataSet();adapter.Fill(DSet, "工作人员表");dataGridView1.AutoGenerateColumns = true;dataGridView1.DataSource = DSet.Tables[0].DefaultView;connection.Close();string connString = "Data Source=(local);Initial Catalog=Factory;Integrated Security=True;";SqlConnection connection = new SqlConnection(connString);connection.Open();if (textBox1.Text.Length == 0){linkLabel1.Visible = true;}else if (textBox2.Text.Length == 0){linkLabel1.Visible = false;linkLabel2.Visible = true;}else{linkLabel1.Visible = false;linkLabel2.Visible = false; ;string data = string.Format("insert into 工作人员表values('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "','{0}','" + comboBox2.Text +"')",dateTimePicker1.Value.ToString("yyyy/MM/dd")); //写成comboBox1.SelectedText不行,记得区分SqlCommand com = new SqlCommand(data, connection);int m = com.ExecuteNonQuery();if (m != 0)MessageBox.Show("插入成功!");elseMessageBox.Show("不好意思,插入不成功,请重新插入!");}connection.Close();string connString = "Data Source=(local);Initial Catalog=Factory;Integrated Security=True;";SqlConnection connection = new SqlConnection(connString);connection.Open();string id = dataGridView2.CurrentRow.Cells["人员编号"].Value.ToString();//string data = "delete from 工作人员表where 人员编号? = '" + id + "'";SqlCommand com = new SqlCommand(data, connection);int m = com.ExecuteNonQuery();if (m != 0)MessageBox.Show("删¦除成功!");elseMessageBox.Show("不好意思,删除不成功,请重新删¦除!");this.dataGridView2.Rows.Remove(this.dataGridView2.CurrentRow);//connection.Close();string connString = "Data Source=(local);Initial Catalog=Factory;Integrated Security=True;";SqlConnection connection = new SqlConnection(connString);connection.Open();string人员编号= dataGridView3.CurrentRow.Cells["人员编号"].Value.ToString();//string姓名= dataGridView3.CurrentRow.Cells["姓名"].Value.ToString();string性别= dataGridView3.CurrentRow.Cells["性别"].Value.ToString();DateTime出生日期=Convert.ToDateTime(dataGridView3.CurrentRow.Cells["出生日期"].Value.ToString().Trim());// DateTime 出生日期= Convert.ToDateTime(dataGridView3.CurrentRow.Cells["出生日期"].Value.ToString()); ////this.dataGridView3.CurrentRow.Cells["出生日期"].Value.ToString();string职务= dataGridView3.CurrentRow.Cells["职务"].Value.ToString();string data = string.Format("update 工作Á人员表set 人员编À号= '" + 人员编À号+ "',姓名= '" + 姓名+ "',性别= '" + 性别+ "',出生日期={0},职务= '" + 职务?+ "' where 人员编号= '" + 人员编号+ "'",出生日期.ToString("yyyy/MM/dd"));SqlCommand com = new SqlCommand(data, connection);int m = com.ExecuteNonQuery();if (m != 0)MessageBox.Show("更新成功!");elseMessageBox.Show("不好意思,更新不成功,请重新更新!");this.dataGridView3.Update();connection.Close();三、运行结果查询:插入:四、实验总结要求个人填写(实验中发现的问题和解决的办法)这次实验是对嵌入式SQL的综合运用,我使用的是C#语言。
SQL实验报告(优秀范文5篇)

SQL实验报告(优秀范文5篇)第一篇:SQL实验报告实验四触发器实验(一)after触发器(1 1)在l l i neitem 表上定义一个 after 触发器, , 当修改列项目e e xtendedprice d i scountx tax 时, , 要把 s orders 表得to o tal pri ce e 一起修改, , 以保证数据一致性C RE ATE T RIGGERtrig _line ite m_ pr ice_ update on line it em fo rupda teaasbegin i f(UPDATE(ex tend edprice)o r UPDATE(tax)or UPD AT E(di scou nt))begin-—声明游标变量指向 inserted 表d eclarecursor_inserted c urs orrea d_onlyofor select order key,linenu mber,exte nd edpr ice, dis coun t, taxfromin ser ted—-息信找查取获量变明声ﻩ声明变量获取查找信息de clare order key in t, @linenumb erint,exte nd edpricereal,disscount real,tax real—-打开游标epoﻩen cursor_i ns ert ed—-标游取读ﻩ读取游标fe tchnextfrom cur sor _i ns erte dint o@o rderkey, @lin enumber,eext ende dprice, @di scount,t axwwhi le FETC H_S TATUS =0 nigebﻩnﻩ—-声明一个变量保存重新计算得新价格cedﻩﻩecl are @n ew_tota lpri cer ealﻩ select @n ew_t otal price= @ext en dedpr ice *(1 -@di scou nt)*(1 +@tax)—-用新得总价格变量更新 orders 表得 t ot alprice puﻩﻩupdate orde rsse t tot alpri ce= new_totalprice where or derkey=orde rkeyen hctefﻩext f ro m cur sor_i nser ted int o@order ke y, @li nenum ber, @ex tende dp rice,discoun t, @taxdneﻩllaedﻩlocate c ur sor_i nser te deend end ﻩ(2)在在 linei tem表上定义一个 aftr er 触发器, , 当增加一项订单明细时, ,自动修改 s orders 表得 total p rice, 以保证数据一致性CREATE TR IGGER tri g_ lineit em_price_ in sert on l ine item ffor inse rta sbegin ——向指量变标游明声ﻩ声明游标变量指向ins erted 表de clarec ursor_inse rtedcursorread_ onl yﻩ for s ele ct orderkey,linenumbe r,ex te ndedp ric e,di scou nt,t axfrom insserte d--声明变量获取查找信息edﻩeclare @orde rk eyint, @lin enumber int,e xten dedp ricereal, @discountreal, @ta xreal -—ﻩ-打开游标open cursor_i ns erte d--ﻩ-读取游标fe tc hnex tf romcu rsor_ins ertedinto@o rd erkey,li nen umbeerr, ex ten ded pric e,dis count,tax ihwﻩile @@FE TCH_ STATU S=0 ebﻩegin-—格价新得算计新重存保量变个一明声ﻩﻩ声明一个变量保存重新计算得新价格cedﻩclare @n ew_tot alprice realcelesﻩct new _to ta lprice= @extend edp rice *(1-d is count)*(1+tax)—-新更量变格价总得新用ﻩﻩ用新得总价格变量更新orders 表得totalpri ceﻩ u pda teor ders s ett ota lpric e=total pric e+ @new_ tota lpr ice wwhhe re o rderke y=orderkeytefﻩetch next from cursor_ ins erte dinto o rder key, @l inen umber,e xtendeddp ric e, @disc ou nt, @t axeend aedﻩdeall oca te cu rsor_in serted en d(3)在l in e ite m表上定义一个a ft er触发器, , 当删除一项订单明细记录时, ,自动修改 orders 表得 tot a lprice, 以保证数据一致性CREATE TRI GG ER trig _line item_price_de let eon line item fo r de let eAAS begin--声明游标变量指向delet ed 表de clar e curso r_d eleted cursorre ad _on lyesrofﻩﻩele ctord erk ey,line numbe r,extende dp rice,discoun t, taxfromdel eted-ﻩ--声明变量获取查找信息declare ord erkey int,linenum be rint,extendedp ri ce r eal,discou nt real,ta xreal -—ﻩ-打开游标epoﻩen c urso r_ deleted——标游取读ﻩ读取游标efﻩetch next fr om cur sor_delete d in toorder ke y,l inenumb er,ext enddedprice, @di scoun t,taxwh ile@FETCH_STATUS=0begi n-—声明一个变量保存重新计算得新价格ﻩ declare @ne w_ to talpric erealﻩsselec t@new_t otalpr ice= @exte nde dpri ce*(1-@disco unt)*(1+ tax)-ﻩ-—用新得总价格变量更新orders 表得tot alp rice uﻩﻩupd ateorders set t otalpri ce=to talpr ice-@new _totalp rice wh er e order key= @ord erkeyfetchn ext f rom cursor_inse rt ed in to orderkey, @line numbe r,extendeeddprice, @d iscou nt,t ax dneﻩndddeal lo cat e cur sor_inse rted eend((4 4))验证 up d at e触发器—-查瞧号订单得 to ta a l pr i ceselec t*fro o mo o r ders whereorde r key=1 8 30;—-查瞧明细表得相关信息se l ect *f ro mlin ei i te e mw here or de e r key=183 0and l ine num m be e r =1;——验证 e update 触发器updat elineitem set t ax=tax+0、05whe re orderkey=1830;(二)i i n steadof触发器((1))在在 lineit em 表上定义一个ins tead o fupda te触发器, 当修改明细表中得数量量quan ti ty 时, 应先检查供应表par tsupp 得av ai lqty 就是否足够, 不足够则拒绝执行, 否则执行并修改相应数值以保证数据一致性于由于 in steadof 触发器更新某个表会使得该表上其她不满足更新列不能更新,因因用此逆向思维使用 a fter 触发器实现相同效果即先更新 qu antity, 再比较av ailqqtty, 如果满足更新数量, 就修改partsupp 得表得 a vailqty, 如果不满足, 则把lineitem得quantity 更新之后得数据重新修改回来ccreate trigge r trig_lin eit em_quanti ty_ upda teonli neit em f or upda teas begin if UPDATE(qu ant ity)bbegin ——向指别分量变标游明声ﻩ声明游标变量分别指向 i nserted 表与 d el eted 表edﻩdeclare c urso r_inser tedcur sorr ead_on lyfortcelesﻩﻩtorde rkey, partk ey,s uppkey,lin enum ber, quantit yfr om i nserteddecl arecursor_de leted c urs orrea d_ onl yf or select quantityfr om deleted-—息信找查取获量变明声ﻩ声明变量获取查找信息decl are@qu an tity _dif f_lineitem i nt,q uanti ty_pa rtsup p i nt cedﻩclare suppkey int, @par tke y in t,o rd erkey i nt,unenilﻩﻩum ber int ,qty _inserted in t , @qty_deleted int--打开游标ruc nepoﻩrsor_in sert ed poﻩopen cur sor_d eleted-—量变给赋值数标游取读ﻩ读取游标数值赋给变量fﻩfet chnext fromcu rsor_ insert edﻩiinto or de rk ey,pa rtkey, @suppk ey, @line nu mber, @qty _ins erte df et chnext fromcursor _d eletedint o q ty _de lete dwhi le fe tch_st atus=0 gebﻩegin--计算订单明细修改时, 订购数量得变化值inserte d表项-d elet ed表项ssel ect quantity_d if f_ li neit em= @q ty _in se rte d—@@q ty_deleteedﻩ--从parts upp 表获取ava ilq ty值, 注意partsupp 表得主键为(partk ey,suppkeey)tcelesﻩﻩt@quanti ty_p ar tsupp =av ailq ty fro m pa rtsu ppwﻩﻩwh er e suppkey= suppke yand part key= @par tk ey-—断判始开ﻩﻩ开始判断gebﻩbegi nfiﻩf quant ity _d iff_ lin eite m=0ﻩﻩ p rin t“ 更新得数量与原表中得值相同, 不需要更新”e ls eif @quantit y_d iff_lin eitem 〈=q uantity_partsuppﻩbe ginﻩpuﻩﻩpd ate partsupps et avail qty= availqty-@qua ntit y_d iff_li ne item ﻩpus erehwﻩppkey=suppkeyandp artkey= @par tke yﻩﻩ p rint “ 两个表都更新成功’ ﻩﻩﻩneﻩndels eigebﻩﻩinﻩuﻩﻩupdate li nei temsetquantit y=quantity+ @quanti ty_diff_linei temwhe re o rd erke y=@orde rke y and li nenu mber= @liine numberﻩp ri nt '更新失败”ﻩﻩendﻩ e nd efﻩﻩetch ne xtfr om c urso r_i nsertedi nto @ord erke y, @partkey,s upp key, @linenumb er, @qt y_ ins ert edf etch ne xt from curso r_de leted into @qt y_d elet ed dneﻩndd eallocat e cur sor _i nserte ddealloc at e cursor_de le ted eend eend(2)在在 l ineite m表上定义一个 instea d of in sert 触发器, 当插入明细表中一条记录时时, 应先检查供应表par tsupp 得得 ava il qt y就是否足够qu anti ty 得数量c rea te t rig ger tri g_lineitem_q ua nti ty_ insertonline item iinstead of inser t as bbegin-—声明游标变量指向 inserte d表d eclar e cur sor_inserte dcur sorrea d_ only f orsﻩﻩselect or derk ey,pa rtkey,sup pk ey, lin en umber,q uantityf rom ins er ted-—声明变量获取查找信息dec lare quantity int, @av ailq ty i nt, @suppkeyin t, @partkeyinntt, @o rderkey int, @linenu mber int-—标游开打ﻩ打开游标c nepoﻩcurs or_ins erted -ﻩ-—读取游标f etc hnext fro mcursor_insert edint o@orde rkey,partkey,@@ssuppkey, @linenumber,qu antity wh ile @@FETCH_S TATUS= 0igebﻩin--为变量赋值a tcelesﻩavailqtyy==av ai lqt y fr ompartsuppwﻩwhe re suppkey =@su ppk ey and part ke y= partke yﻩ if @quant ity 〈= @avail qt y-—如果可以更新bﻩbegin /ﻩﻩﻩ/*将将 insert ed 表中得记录插入到明细表*/ ﻩsniﻩserti nto l ineite m select *from i nsertedro=yekredroerehwﻩﻩrderk ey andlinenumb er = @linenumber */ﻩﻩ新更时同ﻩ*同时更新 part supp 表得数量*/ﻩﻩuupd ate pa rtsup pset a vailqty=availqty-@quanti tyﻩerehwﻩe sup pke y= @sup pkey and partkey=part key ppr int ’paarts upp 表有足够得货物可以满足 lin eitem 得quan tityy, 插入成功’endelsebeginﻩﻩ p rintt''pa rt sup p表没有足够得货物可以满足 l ineitem 得得q uantity,插入失败’dneﻩfﻩﻩfetc h next from curso r_ins ert ed in to@ord erkey, partkey, suppkey, @liinenumbe r, qu antity eﻩen ddeall ocat ecursor_ inserted end(3)在在 line ite m表上定义一个 inste ad of del ete 触发器,当当删除明细表中记录时时, 同时改变表供应表 partsupp 得ava il qtyy数值 c re ate trigge r tri g_ lin eit em_quanti ty_ del ete o n line item inste ad of del ete as be gin—-声明游标变量指向deleted 表de cla re curs or_ del eted c ursorread _only forlesﻩﻩelect or derke y, par tkey,sup pkey, linenumbe r,quan tity fr om deleted -ﻩ--声明变量decl are s upp key i nt, par tke yint, @orde rkey int,linen umb erint, @quaant it y int—-标游开打ﻩ打开游标opencursor_deleted-—标游取读ﻩ读取游标ffetch next fr omcurs or _del et edin to @ord erkey , @partkey,s uppkeey, @lin en umber,q ua ntitywhi leFFET CH_ STATUS=0 igebﻩin*/*除删ﻩ*删除*/ﻩ de let e fromlineite m where linenu mber= line number and o rde rkey =ordder key*/新更时同ﻩ同时更新 pa rt supp 表得数量*/u pdateparts uppse tavailqt y=a vai lq ty+quant ityﻩ where s uppke y= @s uppkey a nd par tk ey= @p ar tkeyﻩ p rin t’ 删除成功, 并且已经把货物数量归还到 p ar tsup p里“ fﻩﻩfetc h ne xt fr omcurso r_del etedinto @ord er ke y,p ar tkey,@@suppkey, @lin enu mber,quanti ty neﻩnd edﻩea lloc ate cursor_ delete dend(4)验证 update 触发器--查瞧li neit em 得quan tit y select*fr omlin eit em whe re or derk ey =1830and li nenum ber=1;——查询partsupp 表得ava ilqt y se lect * from part supp w here suppk ey =(selectsupp key fr omlin eitem w here ord erkey=18 30)and partk ey=(s elec t part key from lin eite mwh er eorder key =18 30 a nd linenu mber=1)---更新数量过大——更新得值与原值相同---更新到+ + 2 00 数量, , 成功updateli neitem setquant ity=q uanti ty+ 200where order key=1830and lin en umber =1;--更新 +2 00成功后l ineite m得 quanti ty y 变化——更新+200 成功后par ts upp 表得a va ilqty 变化实验到此。
嵌入式实训报告范文2篇2

嵌入式实训报告范文 (2)嵌入式实训报告范文 (2)精选2篇(一)嵌入式实训报告一、实训背景嵌入式系统是一种以具体任务为中心,集成了硬件与软件的计算机系统。
由于其体积小、功耗低、功能强大等特点,嵌入式系统被广泛应用于各个领域,如家电、汽车、医疗等。
通过参与嵌入式实训,我希望能够掌握嵌入式开发的基本原理和方法,提高自己的实践能力。
二、实训目标1.掌握嵌入式系统的基本知识和开发工具的使用;2.了解嵌入式系统的硬件架构和软件设计流程;3.能够根据需求设计并实现简单的嵌入式系统。
三、实训内容1.学习嵌入式系统基础知识:通过课堂教学和自主学习,了解了嵌入式系统的概念、特点及应用领域。
深入学习了ARM架构和C语言的基本知识,并进行了相应的实践操作。
2.学习嵌入式开发工具的使用:学习了Keil MDK和IAR Embedded Workbench等常用的嵌入式开发工具的安装和配置方法。
通过实操操作,掌握了调试、编译、下载等基本功能的使用。
3.学习嵌入式系统设计流程:了解了嵌入式软件开发的常用流程,包括需求分析、系统设计、编码实现、调试测试、系统验证等。
通过案例分析和实践操作,对嵌入式系统设计流程有了更深入的了解。
4.设计并实现简单的嵌入式系统:根据实训要求,我选择了一个简单的嵌入式系统项目,通过分析需求、设计系统架构、编写软件代码、调试测试等环节,最终成功完成了项目。
四、实训总结及收获通过参与嵌入式实训,我不仅掌握了嵌入式系统的基本知识和开发工具的使用,还锻炼了自己的实践能力。
我深刻认识到嵌入式系统开发需要全面的知识储备和较高的技术水平,同时也需要良好的分析、设计和沟通能力。
通过实训,我对嵌入式系统开发流程有了更深入的理解,对嵌入式系统的设计和开发也有了更高的认识和要求。
在未来的学习和工作中,我会继续深入学习嵌入式系统开发相关知识,并不断提高自己的实践能力。
嵌入式系统是未来的发展方向,通过不断探索和实践,我相信我能够在这个领域取得更好的成果。
实验五通过嵌入式SQL访问数据库

数据库系统概论课程实验报告班级计科二班学号2013221104210076 姓名曹力一,各种方式简介ESQL嵌入式sql(embedded sql)是将sql语句嵌入到程序设计语言中,如C、C++和java,这些称之为主语言。
将sql嵌入到高级语言中,sql负责数据的处理,高级语言负责程序的控制。
这时候程序会有两种不同的计算机模型语言,两者是如何通信呢?1、向主语言传递sql执行的状态信息,主语言通过此信息来控制程序流程。
主要通过SQL通信区(SQL Communication Area)SQLCA实现,SQLCA中有一个变量SQLCODE用来存放执行SQL所返回的代码,成功则返回预定义代码SUCCESS,否则返回错误代码。
2、主语言提供参数,主要用主变量(Host Variable)实现。
主变量按功能不同可以分为,输入主变量和输出主变量。
一个主变量附带一个指示变量,它可以检查变量是否为空值,是否被截断。
3、SQL将查询的结果交给主语言处理,主要通过主变量和游标实现。
SQL是面向集合的,一条sql可能产生多条记录。
而主语言是面向记录的,一组主变量只能处理一条记录。
所以游标的得来就是处理SQL得到的数据集合,让其指向某一条记录。
特点⏹⒈综合统一⏹ 2. 高度非过程化⏹ 3. 面向集合的操作方式⏹ 4. 同一种语法结构提供两种使用方式⏹ 5. 语言简捷,易学易用三、PL/SQLPL/SQL(procedural language/SQL)是编写数据库存储过程的一种过程语言。
它结合了SQL的数据操作能力和过程话语言的流程控制能力,是SQL的过程化扩展。
格式如下:create procedure 过程名(参数1,参数2,……)s<PL/SQL>块;优点:⏹a提供了在服务器端快速执行SQL语句的有效途径⏹降低了客户机和服务器间的通信量⏹有利于集中控制⏹方便维护四、ODBCODBC可以连接不同的RDBMS,是微软公司开放服务体系中有关数据库的一个组成部分,它建立了一组规范,并提供了一组访问数据库的标准API。
实验4嵌入式SQL和ODBC的使用

实验4 嵌入式SQL和ODBC的使用实验人:田超()黄伟()实验目的1.熟悉ODBC的配置和使用2.熟悉嵌入式SQL编程3.巩固SQL的知识实验平台1.OS:WindowsXP2.DBMS:SQLServer2000piler:Visual C++ 6.0预备知识1)嵌入式SQL编程:嵌入式SQL由SQL语句和C/C++代码组成。
其中SQL语句由预处理器翻译成C或C++的源代码。
对预处理后的源代码进行编译、连接生成可执行程序后方可运行。
●SQL预处理器SQLServer的预处理程序是nsqlprep.exe。
其常用的语法格式如下:nsqlprep 程序文档名⏹nsqlprep详细的语法格式以及参数意义,请看联机帮助。
经查阅联机帮助,nsqlprep的语法格式如下:nsqlprep program_file_name [/SQLACCESS | /NOSQLACCESS][/FLAGGER {ENTRY | NONE}] [/DB [server_name.]database_name/PASS {login[.password] | $INTEGRATED}] [/BIND file_name][/MSG file_name] [/NOLOGO] [/PLAN name] [/NOLINES][/user_defined_option]⏹要求程序文档名的后缀为.sqc,可以省略。
⏹预编译后得到的文档,与程序文档同名,后缀为.c;放在与程序文档名同一个路径下nsqlprep.exe在SQLServer的安装目录的MSSQL\Binn下。
在本机中SQLServer的安装目录是C:\Program Files\Microsoft SQL Server,nsqlprep.exe在C:\Program Files\Microsoft SQL Server\MSSQL\Binn。
由于默认的安装方式(典型安装)并没有安装应用程序nsqlprep.exe,因此,需要把本机中E:\院内学习工作\大三\数据库\SQLServer2000个人版\x86\binn目录下的内容拷贝到该目录下。
实验4PLSQL程序设计(控制结构和嵌入式SQL)

实验4PLSQL程序设计(控制结构和嵌入式SQL)《数据库开发技术》课程之实验四控制结构和嵌入式SQL一、实验目的1.掌握PL/SQL程序设计的基本知识。
2.掌握PL/SQL中控制结构的使用。
具体包括:选择结构(IF语句和CASE语句);循环结构(三种循环语句):3.掌握PL/SQL中SELECT语句和DML语句的正确使用方法。
二、实验内容和要求1.通过CASE语句判断7788雇员的工资等级后输出,工资等级划分条件是:3000(含)以上为高,1500(含)至3000为中,低于1500为低。
执行结果形式如下:工资等级:高PL/SQL 过程已成功完成。
2.用PL/SQL的FOR循环输出以下实心三角形:1 *2 ***3 *****4 *******5 *********3.先创建d_asc表。
再编写一个匿名PL/SQL块,实现往此表插入ASCII码值从32至126的码号和相应码值的字符。
(提示:用CHR()函数, 要求分别用两种循环方法实现)。
附加题:用PL/SQL的循环语句编程,求:12+32+52+...+132+152的值。
执行结果为:656PL/SQL 过程已成功完成。
参考数据:CREA TE TABLE SC(SNO NUMBER(5) ,CNO NUMBER(4) ,GRADE NUMBER(3,1) ,PRIMARY KEY(SNO,CNO));INSERT INTO SC V ALUES(95001,5,92);INSERT INTO SC V ALUES(95002,3,80); INSERT INTO SC V ALUES(95001,1,58); INSERT INTO SC V ALUES(95002,2,90); INSERT INTO SC V ALUES(95003,3,NULL); INSERT INTO SC V ALUES(95001,3,70); INSERT INTO SC V ALUES(95002,1,84.5); INSERT INTO SC V ALUES(95003,2,67); INSERT INTO SC V ALUES(95007,1,44); INSERT INTO SC V ALUES(95007,2,45); INSERT INTO SC V ALUES(95007,3,64); INSERT INTO SC V ALUES(95007,4,34); INSERT INTO SC V ALUES(95007,5,50); INSERT INTO SC V ALUES(95007,6,20); INSERT INTO SC V ALUES(95008,1,34.5); INSERT INTO SC V ALUES(95001,2,85); COMMIT;。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
数据库实验报告专业:软件工程班级:093班学号:**********姓名:***目录一、实验目的 -----------------------------------------2二、实验内容 -----------------------------------------21、题目要求 ----------------------------------------22、实现方法 ----------------------------------------2三、实验步骤 -----------------------------------------5四、实验结果 -----------------------------------------6五、体会 ---------------------------------------------61、遇到的问题及解决方法 -----------------------------62、收获及感悟 --------------------------------------6一、实验目的(1)学会利用Pro*C程序设计语言所提供的游标机制,编写程序(.pc)解决实际问题。
(2)上机学习和实践含嵌入式SQL语句的高级程序的编写、编译、连接、执行的相关过程,并学会编译链接时的相关配置。
二、实验内容1、题目要求本实验综合运用前面掌握的内容并进行综合应用。
选定一种开发工具(VC),设计实现一个简单的数据库应用系统,做到界面友好、使用方便。
(一)假设教学数据库中有三张关系表 S、 C、 SC(关系模式如教材所示),查询某学生的成绩明细,如果成绩为NULL,输出信息为“缓考”。
其输出格式模板如下。
成绩明细情况表(姓名:XXX 学号:XXX)----------------------------------------------------------------- 序号课程号课程名成绩-----------------------------------------------------------------1 C101 数据库概论 852 C102 OS 缓考3 C104 软件工程 554 C103 Java语言 80... ... ...-----------------------------------------------------------------平均成绩:XXX名次:XXX(二)将SC表中的“百分制”改为“4分制”,换算关系如下。
百分制分数成绩点数90~100 480~89 370~79 260~69 160以下 02、实现方法#include <stdio.h>#include <string.h>#include <sqlca.h>#include <sqlcpr.h>#include <stdlib.h>int main(){exec sql include sqlca;exec sql begin declare section;char s_no[6];char s_name[10];int sc_grade;char c_no[6];char c_name[10];int point=0;float average = 0.0;int rank;int r = 1;char user_name[50],user_pwd[20],db_name[20];int i = 0;exec sql end declare section;printf("输入登陆信息:\n");printf("Username: "); gets(user_name);printf("Password: "); gets(user_pwd);printf("db_name: "); gets(db_name);exec sql connect :user_name identified by :user_pwd using :db_name; printf("\n……数据库已连接,登陆成功 \n");printf("\n student number: ");scanf("%s",&s_no);/* 成绩明细情况表 */exec sql select snameinto :s_namefrom swhere sno=:s_no;system("cls");printf("\n 成绩明细情况表 (姓名:%s学号:%s)",s_name,s_no);printf("\n --------------------------------------------");printf("\n 序号课程号课程名成绩 ");printf("\n --------------------------------------------");exec sql declare sx cursor forselect o,ame,sc.gradefrom sc,cwhere o=oand sc.sno=:s_no;exec sql open sx;while(1){exec sql fetch sx into :c_no,:c_name,:sc_grade;if(sqlca.sqlcode == 1403) break;i++;if(sc_grade>0 && sc_grade<100)printf("\n %d %s %s %d",i,c_no,c_name,sc_grade); elseprintf("\n %d %s %s 缓考",i,c_no,c_name);}printf("\n --------------------------------------------\n");exec sql close sx;/* 平均成绩与名次 */exec sql select avg(sc.grade)into :averagefrom scgroup by snohaving sno=:s_no;printf("\n 平均成绩:%f \n",average);exec sql declare sx2 cursor forselect avg(grade)from scgroup by sno;exec sql open sx2;while(1){exec sql fetch sx2 into :rank;if(sqlca.sqlcode == 1403) break;if(rank > average) r++;}printf(" 名次:%d \n\n",r);exec sql close sx2;/* 分制转换 */exec sql declare sx3 cursor forselect gradefrom sc;printf("\n 分制转换表 ");printf("\n ---------------------------------------------");printf("\n 百分制成绩成绩点数 ");printf("\n ---------------------------------------------");exec sql open sx3;while(1){exec sql fetch sx3 into :sc_grade;if(sqlca.sqlcode == 1403) break;if(sc_grade!=-1){if(sc_grade>90 && sc_grade<100)point=4;else if(sc_grade>80 && sc_grade<90)point=3;else if(sc_grade>70 && sc_grade<80)point=2;else if(sc_grade>60 && sc_grade<70)point=1;elsepoint=0;printf("\n %d %d ",sc_grade,point);}elseprintf("\n %s号课程缓考",c_no);sc_grade=-1;}printf("\n -----------------------------------------------\n");exec sql close sx3;exec sql commit release;}三、实验步骤(1)已安装VC++6.0和Oracle10g标准版;(2)启动OracleOraHome90TNSListener和OracleServiceORCL服务;(3)已建立oracle相应帐户;(4)在system帐户下,已建立三个关系模式S、SC和C;(5)使用oracle10g的预编译器proc.exe, 将pro*c文件(.pc文件)编译为c文件(.c文件);(6)使用VC++6.0对.c文件编译、链接、执行、执行(分两步:编译前要配置,链接、执行前也要配置)。
四、实验结果五、体会1、遇到的问题及解决方法问题:总是输出乱码解决:连接数据库时输入db_name的orcl 。
问题:只设置一个游标时不能输出分制转换的内容解决:设置三个游标,每次查询时都打开游标。
问题:平均成绩输出是乱码解决:定义变量average时初始化为0.0。
2、收获及感悟学习了这么久的数据库的理论知识,通过这次实验终于能实现用高级语言解决实际问题了,觉得很有意义。
同时更加深了对嵌入式SQL语言的理解。
也感觉的自己的所学的还远远不够,还有好多知识没有学到位,也希望在今后的学习过程中加强自己上机动手的实践能力。