『壹』 用java编程的通过SQL连接数据库的商品库存管理系统的源代码
package com.company.;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class BaseDao {
// 数据库驱动
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//url
String url = "jdbc:sqlserver://数据库ip:端口号;databaseName=数据库名;";
//用户名
String uname = "数据库用户名";
//密码
String pwd = "数据库密码";
/**
* 获得连接对象
* @return
*/
protected Connection getCon(){
//返回的连接
Connection con = null;
try {
//载入驱动
Class.forName(driver);
//得到连接
con = DriverManager.getConnection(url, uname, pwd);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
/**
* 关闭数据库
* @param con
* @param stmt
* @param rs
*/
protected void closeDB(Connection con, Statement stmt, ResultSet rs){
if(rs != null){
try {
//关闭结果集
rs.close();
rs = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(stmt != null){
try {
//关闭语句对象
stmt.close();
stmt = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(con != null){
try {
//关闭连接对象
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
protected void closeDB(Connection con, PreparedStatement pstmt, ResultSet rs){
if(rs != null){
//关闭结果集
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(pstmt != null){
try {
pstmt.close();
pstmt = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(con != null){
try {
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
这个是我写的一个基本的连接sql2005数据库的代码,.! 不知道你能不能用,! 你看一下吧, 连接的时候需要sqljdbc.jar数据库驱动,!
『贰』 求一个C语言程序。小型数据库。一个管理系统。功能包括:查询,修改等等。。带解释的 谢谢~!
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "math.h"
#include "ctype.h"
#include "string.h"
#define MAX 4
#define TERM 6
struct STUD{
unsigned number;
char name[20];
unsigned score[MAX];
float average;
struct STUD *next;
};
struct CLASS{
unsigned no;
unsigned students;
float score[MAX];
float average;
struct STUD *first;
};
//输出所有学生的成绩及名次
void output(struct CLASS *pclass)
{
struct STUD *p;
int n=0;
printf("Class:%u\t number of students:%u\n",pclass->no ,pclass->students );
printf("number name math physics politics "
"english average place\n");
for(n=1,p=pclass->first ;p!=NULL;p=p->next ,++n)
printf("%-8u%-12s%-8u%-8u%-8u%-8u%-10.2f%-d\n",
p->number ,p->name ,p->score[0] ,p->score [1],
p->score [2],p->score [3],p->average ,n);
}
//按平均成绩排序
void sort(struct CLASS *pclass)
{
struct STUD *p, *next, *last;
int m,n;
for(m=0;m<pclass->students -1;m++)
for(last=p=pclass->first ,n=0;n<pclass->students-1-m;
n++,last=p,p=p->next)
if(p->average<p->next->average){
next=p->next;
if(p!=pclass->first)
last->next=next;
else
pclass->first=next;
next->next=p;
p=next;
}
}
char *cou[MAX]={"math","phusics","politics","english"};
//将链表所有接点写入文件
void write_file(struct CLASS *pclass,FILE *myfile)
{
struct STUD *p;
for(p=pclass->first;p!=NULL;p=p->next)
fwrite(p,sizeof(struct STUD),1,myfile);
}
//从文件中读数据重建链表
void read_file(struct CLASS *pclass,FILE *myfile)
{
struct STUD buf,*p,*tail;
int n;
for(tail=pclass->first ,n=0;n<pclass->students ;tail=p,++n){
if(fread(&buf,sizeof(struct STUD),1,myfile)!=1){
pclass->students =n;
break;
}
p=(struct STUD *) malloc(sizeof(struct STUD));
*p=buf;
//连接成先进先出链表
if(pclass->first==NULL)
pclass->first =p;
else
tail->next =p;
p->next =NULL;
}
}
//增加信息
void insert(struct CLASS *pclass)
{
struct STUD *p,*current,*last;
int k,ch,flag;
do{
p=(struct STUD *) malloc(sizeof(struct STUD));
printf("\ninput number and name of student:");
scanf("%u%s",&p->number ,p->name );
while(1){
for(flag=1,k=0;k<MAX;++k){
printf("\niput %s:",cou[k]);
scanf("%u",&p->score[k]);
if(p->score[k]>100)
flag=0;
}
if(flag) break;
printf("score error\n");
}
p->average =(float)(p->score[0]+p->score[1]+p->score[2]+p->score[3])/4;
//找插入点
for(last=current=pclass->first;current->next&¤t->average>p->average;
last=current,current=current->next );
if(current->next ==NULL&¤t->average>p->average){
p->next =NULL;
current->next =p;
}
else{
p->next =current;
if(current==pclass->first)
pclass->first =p;
else
last->next =p;
}
pclass->students ++;
printf("continue?(y/n)");
while(isspace(ch=getchar()));
}while (ch=='y'||ch=='Y');
}
//删除学生
void delete_stu(struct CLASS *pclass)
{
unsigned ch;
struct STUD *current,*last,*p;
do{
printf("\ninput number of student:");
scanf("%u",&p->number,&ch);
for(last=current=pclass->first;current!=NULL&¤t->number!=ch;
last=current,current=current->next);
if(current!=NULL){
if(current!=pclass->first)
last->next=current->next;
else
pclass->first=current->next;
free(current);
pclass->students--;
}
else
fprintf(stderr,"error:number of student!\n");
printf("continue?(y/n)");
while(isspace(ch=getchar()));
}while (ch=='y'||ch=='Y');
}
void create(struct CLASS *pclass)
{
struct STUD *p,*tmp=NULL;
int n=0,k,ch,flag;
do{
p=(struct STUD *) malloc(sizeof(struct STUD));
printf("\ninput number and name of student:");
scanf("%u%s",&p->number ,p->name );
while(1){
for(flag=1,k=0;k<MAX;++k){
printf("\niput %s:",cou[k]);
scanf("%u",&p->score[k]);
if(p->score[k]>100)
flag=0;
}
if(flag) break;
printf("score error\n");
}
p->average =(float)(p->score[0]+p->score[1]+p->score[2]+p->score[3])/4;
p->next =pclass->first ;
pclass->first =p;
++n;
printf("continue?(y/n)");
while(isspace(ch=getchar()));
}while (ch=='y'||ch=='Y');
pclass->students =n;
}
//计算平均分
void average(struct CLASS *pclass)
{
static double general[MAX],g;
struct STUD *p;
int i;
for(p=pclass->first;p!=NULL;p=p->next)
for(i=0;i<MAX;++i)
general[i]+=p->score[i];
printf("\n math physics politics english\n");
for(i=0;i<MAX;++i){
pclass->score[i]=general[i]/pclass->students ;
printf("%10.2f",pclass->score[i]);
g+=general[i];
}
pclass->average =g/(MAX*pclass->students );
printf("\ngeneral average:%10.2f\n",pclass->average );
}
void main()
{
struct CLASS cla;
FILE *fp;
int flag=1,k;
char c,*menu[]={
"\n1:insert a student\n",
"2:delete a student\n",
"3:save into file\n",
"4:print class score list\n",
"5:stat average\n",
"0:exit\n",
"\nselect[0-6]:"
};
if((fp=fopen("students.dat","rb"))==NULL){
printf("input number of class:");
scanf("%u",&cla.no);
cla.students=0;
cla.first=0;
create(&cla);
sort(&cla);
}
else{
fread(&cla,sizeof(struct CLASS),1,fp);
cla.first=NULL;
read_file(&cla,fp);
fclose(fp);
}
while(flag){
for(k=0;k<=TERM;k++)
printf("%s",menu[k]);
scanf("%d",&k);
switch (k){
case 1:
insert(&cla);
break;
case 2:
delete_stu(&cla);
break;
case 3:
if((fp=fopen("students.dat","wb"))==NULL){
fprintf(stderr,"error:can't create file students!\n");
return;
}
fwrite(&cla,sizeof(struct CLASS),1,fp);
write_file(&cla,fp);
fclose(fp);
break;
case 4:
output(&cla);
break;
case 5:
average(&cla);
break;
case 0:
printf("save yout change?(y/n)");
scanf("%c%*c",&c);
c=='y'||c=='Y'?(c=1):(c==0);
if(c){
if((fp=fopen("students.dat","wb"))==NULL){
fprintf(stderr,"error:can't create file students!\n");
return;
}
rewind(fp);
fwrite(&cla,sizeof(struct CLASS),1,fp);
write_file (&cla,fp);
fclose(fp);
}
flag=0;
break;
default:
fprintf(stderr,"select error!\n");
}
}
}
『叁』 数据库管理系统的代码是跟windows代码一样运行在内核态的吗
说实话,你提问题提的很模糊,不知道是什么意思?你所谓的代码是源代码还是指返回码
如果是源代码的话,给你以下的答案:
数据库的源代码是基于系统之上运行的,也就是说在运行上,实际上是会调用系统的功能的,当然不一定是windows的
windows的代码的话,是基于本身的基本架构来做的,肯定是先实现了基本核心,然后才实现外围的一些功能的。
如果是返回码的话,那就情况又不一样了。
数据库的返回码一般分三种
1.系统设计人员设定的
2.数据库上的返回码
3.数据库调用系统功能的返回码
而系统的返回码则主要是系统开发层面上的