不知楼主是写的Java程序,还是Jsp。
Java程序在编译时需要将SQLServer驱动的三个jar文件导入再编译。
如果是jsp文件,可以将这三个文件放在容器相应的位置。我只能简单向你介绍一下jdbc,详细内容请参考相关书籍。
Jdbc-Odbc桥方式,JavaSoft桥产品通过ODBC驱动程序提供JDBC访问。一般不用,只是在访问没有JDBC驱动程序的数据库时才使用,例如Access.
本地API,在客户端有相应的API程序来调用底层连接数据库文件。例如:微软的操作系统就集成了访问SQLServer数据库的DLL文件,你只需要用C++写一个API,或者就用微软的开发产品来连接数据库。Oracle的DLL文件是:oci8.dll。
而另为两种差不多,通过服务器为TCP/IP协议开通的端口,远程访问数据库。与上面两种的实现机制不一样。

解决方案 »

  1.   

    补充一句:JDBC一般就使用后面两种中的一种:JDBC网络纯Java驱动程序。
      

  2.   

    sqlserver驱动在
    http://www.microsoft.com/china/sql/downloads/2000/jdbc.asp
    下载
      

  3.   

    Jdbc-Odbc桥方式已经严重落伍了
    建议不要看他   乱费时间
    现在我们java这么流行   哪个数据库会不提供jar文件用jdbc来连数据库呀
      

  4.   

    正好昨天写了个将e:\homework下的文件以二进制方式存到sql server 数据库中去(字段类型为image)
    里面用到了sqlserver jdbc,包含三个jar包 : msbase.jar,mssqlserver.jar,msutil.jar.
    看看对你有没帮助
    /*
     * Created on Oct 2, 2005
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    package com.didoleo.sql;import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    /**
     * @author dido leo
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class SqlOperation {
    static Connection conn=null;
    public static void main(String[] args){
    try{
    String driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
    String serverName="localhost";
    String portName="1433";
    String mydatabase=serverName+":"+portName;
    String url="jdbc:microsoft:sqlserver://"+mydatabase+";DatabaseName=spring"; String username="sa";
    String password="123abc";

    Class.forName(driverName);
    conn=DriverManager.getConnection(url,username,password);
    //将e:\homework\文件保存到数库
    traverse(new File("e:/HomeWork/"),conn);
    //将数据库中数据导成d:\homework文件
    //reverseProcess(conn);


    }catch(ClassNotFoundException e){
    System.out.println("error");
    }catch(SQLException e){
    e.printStackTrace();
    System.out.println("Could not connect to the database");
    }



    }
    public static void process(File dir,Connection conn){

    String sql="Insert into chenhao (filename,picture,filesize) " +
    " values (?,?,?)";
    System.out.println(sql);
    try{
    PreparedStatement pstmt =conn.prepareStatement(sql);
    try{
    byte[] buffer=getBytesFromFile(dir);
    pstmt.setString(1,dir.getName());
    pstmt.setBytes(2,buffer);
    pstmt.setLong(3,dir.length());
    pstmt.executeUpdate();
    pstmt.close();
    System.out.println("processing "+dir.getName()+"  successed ...");
    }catch(IOException ioe){
    //ioe.printStackTrace();
    System.out.println("process put file error"+dir.getName()+" processing failed...");
    }


    }catch(SQLException e){
    e.printStackTrace();
    System.out.println("process put file error"+dir.getName()+"processing failed...");
    System.out.println("process sql error");
    }




    }

    public static void traverse(File dir,Connection conn){
    process(dir,conn);
    if(dir.isDirectory()){
    String[] children=dir.list();
    for(int i=0;i<children.length;i++){
    traverse(new File(dir,children[i]),conn);
    }
    }

    }


    public static void reverseProcess(Connection conn) throws SQLException {
    System.out.println("doing reverseProcess...");
    String sql="Select filename from mypicture  ";
    Statement stmt=conn.createStatement();
    System.out.println("doing createStatement...");
    ResultSet resultSet=stmt.executeQuery(sql);
    System.out.println("doing executeQuery...");
    while(resultSet.next()){
    System.out.println("doing while...");
    String filename=resultSet.getString("filename");
    byte[] buffer=getBytesFromDatabase(conn,filename);
    if(buffer!=null)
    try{
    System.out.println("begin writeinfile "+filename+"...");
    writeinfile("d:\\homework\\"+filename,buffer);
    System.out.println("end writeinfile "+filename+"...");
    }catch(IOException ioe){
    System.out.println("write "+filename+" failed.");
    ioe.printStackTrace();
    }


    }



    }

    public static void writeinfile(String filename,byte[] buffer) throws IOException{
    System.out.println("writein....");
    File file=new File(filename);
    //boolean success=file.createNewFile();
    System.out.println("create file");
    OutputStream os=new FileOutputStream(file);
    System.out.println("create outputstream");
    os.write(buffer);
    System.out.println("writeing...");
    os.close();
    }

    public static byte[] getBytesFromDatabase(Connection conn,String filename) throws SQLException {
    System.out.println("doing getBytesFromDatabase...");

    //String sql="Select picture from mypicture where filename = ? ";
    String sql="select picture from mypicture where filename='"+filename+"'";
    //PreparedStatement pstmt=conn.prepareStatement(sql);
    System.out.println("doing preparedstatement...");
    //pstmt.setString(1,filename);

    byte[] bytes=null;
    try{
    //ResultSet resultSet=pstmt.executeQuery(sql);
    Statement stmt=conn.createStatement();
    ResultSet resultSet=stmt.executeQuery(sql);
    System.out.println(sql);
    System.out.println("doing pstmt.executeQuery...");
    System.out.println("doing "+filename+"...");
    while(resultSet.next()){
    System.out.println("doing resultSet.next()...");
    bytes=resultSet.getBytes("picture");
    }
    }catch(SQLException sqle){
    sqle.printStackTrace();
    }

    return bytes;
    }

    public static byte[] getBytesFromFile(File file) throws IOException {
    InputStream is=new FileInputStream(file);
    long length=file.length();
    if(length>Integer.MAX_VALUE){
    System.out.println("File is too large...");
    throw new IOException("Could not read file ,file is too large...");
    }
    byte[] bytes=new byte[(int)length];
    int offset=0;
    int numRead=0;

    while(offset<bytes.length && (numRead=is.read(bytes,offset,bytes.length-offset))>=0){
    offset+=numRead;
    }
    if(offset<bytes.length){
    throw new IOException("Could not completely read file "+file.getName());
    }
    is.close();
    return bytes;
    }
    }
      

  5.   

    msbase.jar,mssqlserver.jar,msutil.jar 
    这三个文件好想不是 SQl Server 自带吧好象是要自己去下