我这有个原来不知道哪儿copy的例子import java.io.*;
import java.util.*;
import java.sql.*;import java.text.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class writeBean {
private String sample = "";
//Access sample property
public String getSample() {
return sample;
}
//Access sample property
public void setSample(String newValue) {
if (newValue!=null) {
sample = newValue;
}
}
private String filename = "";
//Access sample property
public String getFilename() {
return filename;
}
//Access sample property
public void setFilename(String newValue) {
if (newValue!=null) {
filename = newValue;
}
}
public void gwrite() throws SQLException,IOException
{
PreparedStatement stmt = null;
ResultSet rs = null;
InputStream fin = null;
OutputStream fout = null;
Connection conn=null;
try{
newhua.dbbean db=new newhua.dbbean();
db.InitDatabase();
conn =db.conn;
//conn.setAutoCommit(false);
System.out.println(sample);
System.out.println(filename);
//String filename;
//
//filename="c:/tomcat/webapps/nw/lsdoc/"+sample+".sxw";
String mysql= "select word from tmanuscript where glidenumber='"+sample+"' for update";
System.out.println(mysql);
stmt=conn.prepareStatement(mysql);
//stmt.setString(1,sample);
rs=stmt.executeQuery() ;
//System.out.println();
if(rs.next()) {
System.out.println(sample);
System.out.println(filename);
BLOB blob = ((OracleResultSet)rs).getBLOB("word");
fout = blob.getBinaryOutputStream();
File f = new File(filename);
fin = new FileInputStream(f);
byte[] buffer = new byte[blob.getBufferSize()];
int bytesRead = 0;
while((bytesRead = fin.read(buffer)) != -1)
{
fout.write(buffer, 0, bytesRead);
System.out.println(bytesRead);
} blob = null;
f = null;
buffer = null;
fin.close();
fout.close();
conn.commit();
}
}
catch(Exception ex)
{
ex.printStackTrace(); }
finally {
try {
fin = null;
fout = null;
rs = null;
conn = null;
stmt = null;
}
catch(Exception e) {
e.printStackTrace();
}
}
}public void gread() throws SQLException,IOException
{
Connection conn = null;
PreparedStatement stmt = null;
InputStream in = null;
OutputStream out = null;
BLOB blob = null;
ResultSet rs = null;
try {
newhua.dbbean db=new newhua.dbbean();
db.InitDatabase();
conn =db.conn;
//String filename;
//filename="c:/tomcat/webapps/nw/lsdoc/o_"+sample+".sxw";
String mysql="Select word FROM tmanuscript WHERE glidenumber ='"+sample+"' ";
System.out.println(mysql);
stmt = conn.prepareStatement(mysql);
//stmt.setString(1,"67");
rs = stmt.executeQuery();
if(rs.next()) {
blob = ((OracleResultSet)rs).getBLOB("word");
in = blob.getBinaryStream();
out = new FileOutputStream(filename);
int bufferSize = blob.getBufferSize();
byte[] buffer = new byte[bufferSize];
int bytesRead = 0;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
System.out.println(bytesRead);
}
stmt.clearParameters();
buffer = null;
in.close();
out.close();
conn.commit();
}
}
catch(Exception e) {
e.printStackTrace(); } finally {
try {
in = null;
blob = null;
rs = null;
out = null;
conn = null;
stmt = null;
}
catch(Exception e) { }
} }
}jsp:<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.io.*,java.util.*,java.sql.*,java.text.*,oracle.jdbc.driver.*,oracle.sql.*" %><HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="STYLESHEET" type="text/css" href="css/style.css">
<TITLE>发文--保存</TITLE><script language="javascript">
</script>
</HEAD>
<jsp:useBean id="writeBeanId" scope="session" class="newhua.writeBean" />
<jsp:setProperty name="writeBeanId" property="*" /><BODY BGCOLOR=#CCCCc2 TEXT=#0f0000 LINK=#0000ff ALINK=#cc0000 VLINK=#306898 TOPMARGIN=5 MARGINHEIGHT="5" >
<%!
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}%>
<%
String glidenumber,comenumber,author,editor,buildtime,subject,flag;glidenumber=UnicodeToChinese(request.getParameter("glidenumber")) ;
comenumber=UnicodeToChinese(request.getParameter("comenumber")) ;
author=UnicodeToChinese(request.getParameter("author")) ;
editor=UnicodeToChinese(request.getParameter("editor")) ;
buildtime=UnicodeToChinese(request.getParameter("buildtime")) ;
subject=UnicodeToChinese(request.getParameter("subject")) ;
flag=UnicodeToChinese(request.getParameter("flag")) ;String mysql;
mysql="INSERT INTO SYSTEM.TMANUSCRIPT (COMENUMBER ,GLIDENUMBER ,AUTHOR ,FLAG ,EDITOR ,BUILDTIME,SUBJECT,WORD )";
mysql=mysql+" VALUES ('"+comenumber+"' ,'"+glidenumber+"' ,'"+author+"' ,'"+flag+"' ,'"+editor;
mysql=mysql+" ' ,'"+buildtime+" ' ,'"+subject+"' ,EMPTY_BLOB() )";out.println(mysql);
newhua.dbbean db=new newhua.dbbean();
db.executeSql(mysql);String filename="c:/lsdoc/"+glidenumber+".sxw";
writeBeanId.setFilename(filename);
writeBeanId.setSample(glidenumber);
System.out.println(filename);
System.out.println(glidenumber);
writeBeanId.gwrite() ;response.sendRedirect("search.jsp");
%></BODY>
</HTML>
//重点是要导入oracle的包,其他都一样操作..
import java.util.*;
import java.sql.*;import java.text.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class writeBean {
private String sample = "";
//Access sample property
public String getSample() {
return sample;
}
//Access sample property
public void setSample(String newValue) {
if (newValue!=null) {
sample = newValue;
}
}
private String filename = "";
//Access sample property
public String getFilename() {
return filename;
}
//Access sample property
public void setFilename(String newValue) {
if (newValue!=null) {
filename = newValue;
}
}
public void gwrite() throws SQLException,IOException
{
PreparedStatement stmt = null;
ResultSet rs = null;
InputStream fin = null;
OutputStream fout = null;
Connection conn=null;
try{
newhua.dbbean db=new newhua.dbbean();
db.InitDatabase();
conn =db.conn;
//conn.setAutoCommit(false);
System.out.println(sample);
System.out.println(filename);
//String filename;
//
//filename="c:/tomcat/webapps/nw/lsdoc/"+sample+".sxw";
String mysql= "select word from tmanuscript where glidenumber='"+sample+"' for update";
System.out.println(mysql);
stmt=conn.prepareStatement(mysql);
//stmt.setString(1,sample);
rs=stmt.executeQuery() ;
//System.out.println();
if(rs.next()) {
System.out.println(sample);
System.out.println(filename);
BLOB blob = ((OracleResultSet)rs).getBLOB("word");
fout = blob.getBinaryOutputStream();
File f = new File(filename);
fin = new FileInputStream(f);
byte[] buffer = new byte[blob.getBufferSize()];
int bytesRead = 0;
while((bytesRead = fin.read(buffer)) != -1)
{
fout.write(buffer, 0, bytesRead);
System.out.println(bytesRead);
} blob = null;
f = null;
buffer = null;
fin.close();
fout.close();
conn.commit();
}
}
catch(Exception ex)
{
ex.printStackTrace(); }
finally {
try {
fin = null;
fout = null;
rs = null;
conn = null;
stmt = null;
}
catch(Exception e) {
e.printStackTrace();
}
}
}public void gread() throws SQLException,IOException
{
Connection conn = null;
PreparedStatement stmt = null;
InputStream in = null;
OutputStream out = null;
BLOB blob = null;
ResultSet rs = null;
try {
newhua.dbbean db=new newhua.dbbean();
db.InitDatabase();
conn =db.conn;
//String filename;
//filename="c:/tomcat/webapps/nw/lsdoc/o_"+sample+".sxw";
String mysql="Select word FROM tmanuscript WHERE glidenumber ='"+sample+"' ";
System.out.println(mysql);
stmt = conn.prepareStatement(mysql);
//stmt.setString(1,"67");
rs = stmt.executeQuery();
if(rs.next()) {
blob = ((OracleResultSet)rs).getBLOB("word");
in = blob.getBinaryStream();
out = new FileOutputStream(filename);
int bufferSize = blob.getBufferSize();
byte[] buffer = new byte[bufferSize];
int bytesRead = 0;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
System.out.println(bytesRead);
}
stmt.clearParameters();
buffer = null;
in.close();
out.close();
conn.commit();
}
}
catch(Exception e) {
e.printStackTrace(); } finally {
try {
in = null;
blob = null;
rs = null;
out = null;
conn = null;
stmt = null;
}
catch(Exception e) { }
} }
}jsp:<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.io.*,java.util.*,java.sql.*,java.text.*,oracle.jdbc.driver.*,oracle.sql.*" %><HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="STYLESHEET" type="text/css" href="css/style.css">
<TITLE>发文--保存</TITLE><script language="javascript">
</script>
</HEAD>
<jsp:useBean id="writeBeanId" scope="session" class="newhua.writeBean" />
<jsp:setProperty name="writeBeanId" property="*" /><BODY BGCOLOR=#CCCCc2 TEXT=#0f0000 LINK=#0000ff ALINK=#cc0000 VLINK=#306898 TOPMARGIN=5 MARGINHEIGHT="5" >
<%!
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}%>
<%
String glidenumber,comenumber,author,editor,buildtime,subject,flag;glidenumber=UnicodeToChinese(request.getParameter("glidenumber")) ;
comenumber=UnicodeToChinese(request.getParameter("comenumber")) ;
author=UnicodeToChinese(request.getParameter("author")) ;
editor=UnicodeToChinese(request.getParameter("editor")) ;
buildtime=UnicodeToChinese(request.getParameter("buildtime")) ;
subject=UnicodeToChinese(request.getParameter("subject")) ;
flag=UnicodeToChinese(request.getParameter("flag")) ;String mysql;
mysql="INSERT INTO SYSTEM.TMANUSCRIPT (COMENUMBER ,GLIDENUMBER ,AUTHOR ,FLAG ,EDITOR ,BUILDTIME,SUBJECT,WORD )";
mysql=mysql+" VALUES ('"+comenumber+"' ,'"+glidenumber+"' ,'"+author+"' ,'"+flag+"' ,'"+editor;
mysql=mysql+" ' ,'"+buildtime+" ' ,'"+subject+"' ,EMPTY_BLOB() )";out.println(mysql);
newhua.dbbean db=new newhua.dbbean();
db.executeSql(mysql);String filename="c:/lsdoc/"+glidenumber+".sxw";
writeBeanId.setFilename(filename);
writeBeanId.setSample(glidenumber);
System.out.println(filename);
System.out.println(glidenumber);
writeBeanId.gwrite() ;response.sendRedirect("search.jsp");
%></BODY>
</HTML>
//重点是要导入oracle的包,其他都一样操作..
解决方案 »
- jsp里request获取不到action从数据库里读取到的数据
- struts 传值
- 数据库是db2 时间类型是timestamp 怎么查出 createtime 距离当前时间已经三个月的数据
- struts2中iterator 元素的绝对值和百分比问题
- JS怎么实现查询本机目录下所有文件名称的功能.
- 想问一下参加工作的朋友,现在市场上流行的JAVA主要是哪些技术?
- 讨论下JSF(不是JSP)
- 分页的一些问题,请大家帮忙~!
- 不能forward请求的问题?求救!!!----在线等
- jdbc连oracle数据库的问题!!高分求救
- 单机如何调试JSP(高分)
- 请问有没有JDK1.4帮助文档的中文版啊?
http://expert.csdn.net/Expert/FAQ/List_Room_FAQ_Index.asp?bigclassid=54
http://expert.csdn.net/Expert/topic/945/945944.xml?temp=.850033