不知楼主是写的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协议开通的端口,远程访问数据库。与上面两种的实现机制不一样。
Java程序在编译时需要将SQLServer驱动的三个jar文件导入再编译。
如果是jsp文件,可以将这三个文件放在容器相应的位置。我只能简单向你介绍一下jdbc,详细内容请参考相关书籍。
Jdbc-Odbc桥方式,JavaSoft桥产品通过ODBC驱动程序提供JDBC访问。一般不用,只是在访问没有JDBC驱动程序的数据库时才使用,例如Access.
本地API,在客户端有相应的API程序来调用底层连接数据库文件。例如:微软的操作系统就集成了访问SQLServer数据库的DLL文件,你只需要用C++写一个API,或者就用微软的开发产品来连接数据库。Oracle的DLL文件是:oci8.dll。
而另为两种差不多,通过服务器为TCP/IP协议开通的端口,远程访问数据库。与上面两种的实现机制不一样。
解决方案 »
- JSP 用Ajax技术怎么实现分页?
- S2SH整合Update问题。。。。
- 求教一个问题?
- 求助 !!!!关于poi将JSP导出EXCEL的问题!!!!!![
- SimpleDateFormat.parse的怪问题
- 哪位高手做过容器外调用tomcat的数据池的呀。
- Structs中明细中下拉列表如何映射值?急!!!
- 用<s:iterator>标签从action中的list显示出来的数据怎样再通过set方法返回到action页面中?
- JBoss+Tomcat居然不能编译<jsp:include page="xxx.xxx"/>标记
- 谁有微软的VSS与jb配合的版本控制详细使用说明???
- (给100分!)Weblogic配置JDBC联接缓冲池总是出问题
- 我在部署应用程序时,经常与其他应用程序的jndi命名冲突,请问你们是怎么命名jndi的,我都是以ejb/name来命名
http://www.microsoft.com/china/sql/downloads/2000/jdbc.asp
下载
建议不要看他 乱费时间
现在我们java这么流行 哪个数据库会不提供jar文件用jdbc来连数据库呀
里面用到了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;
}
}
这三个文件好想不是 SQl Server 自带吧好象是要自己去下