import java.sql.*;//JDBC必须导入的包
import java.io.*;
import java.util.*;
public class MyFile {
java.sql.Connection con=null;//必须
java.sql.Statement stmt=null;//必须
java.sql.ResultSet rs=null;//必须
String driverName=null;
String adminName=null;
String adminPWD=null;
private Connection getCon()throws SQLException,ClassNotFoundException{
driverName="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=mydata";//必须
adminName="sa";
adminPWD="wsw";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//必须
con=DriverManager.getConnection(driverName,adminName,adminPWD);//必须
return con;
}
public ResultSet getRs(String sql)throws SQLException,ClassNotFoundException{
//返回的是结果集
stmt=this.getCon().createStatement();//必须
rs=stmt.executeQuery(sql);//必须
return rs;
}
public boolean rsChange(String sql)throws SQLException,ClassNotFoundException{
//返回的是处理的结果,布尔值
boolean bool=true;
stmt=this.getCon().createStatement();
bool=stmt.execute(sql);
return bool;
}
public void CloseAll()throws SQLException,IOException{
//关闭数据库连接
if(con!=null){
if(stmt!=null){
if(rs!=null){
rs.close();
rs=null;
}
stmt.close();
stmt=null;
}
con.close();
con=null;
}
}
做这些之前你还要找到几个包,就是JDBC驱动程序包,如果没有这个包你的程序是不能运行的,还有你的数据库要升级成SP3,不然运行时会出现连接错误!
#include
#include
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun( SLIST *h, int x)
{ SLIST *p, *q, *s;
s=(SLIST *)malloc(sizeof(SLIST));
/**********found**********/
s->data=q;
q=h;
p=h->next;
while(p!=NULL && x>p->data) {
/**********found**********/
q=___2___;
p=p->next;
}
s->next=p;
/**********found**********/
q->next=___3___;
}
SLIST *creatlist(int *a)
{ SLIST *h,*p,*q; int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i
q->data=a[i]; p->next=q; p=q;
}
p->next=0;
return h;
}
void outlist(SLIST *h)
{ SLIST *p;
p=h->next;
if (p==NULL) printf("\nThe list is NULL!\n");
else
{ printf("\nHead");
do { printf("->%d",p->data); p=p->next; } while(p!=NULL);
printf("->End\n");
}
}
main()
{ SLIST *head; int x;
int a[N]={11,12,15,18,19,22,25,29};
head=creatlist(a);
printf("\nThe list before inserting:\n"); outlist(head);
printf("\nEnter a number : "); scanf("%d",&x);
fun(head,x);
printf("\nThe list after inserting:\n"); outlist(head);
开始--设置--控制面板--管理工具--数据源(ODBC)--在"用户DSN"选项中选"添加"安装所需要的驱动程序."SQL SERVER"
import java.sql.*;
public class MSDBdemo {
public static void main(String[] args){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
System.out.println("数据库驱动程序注册成功!");
String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=northwind";
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println("数据库连接成功");
}catch(Exception e){
e.printStackTrace();
System.out.println("数据库连接失败");
}
}
}