Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FileNook
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sanblas
FileNook
Commits
5efa021b
Commit
5efa021b
authored
May 21, 2019
by
andres
Browse files
Options
Downloads
Patches
Plain Diff
Descargar documentossssssssssssssssssssssssssssssssss
parent
0b5e0502
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Source Packages/conexionDB/documentoDB.java
+34
-45
34 additions, 45 deletions
Source Packages/conexionDB/documentoDB.java
Source Packages/servlet/descargarNookSV.java
+39
-4
39 additions, 4 deletions
Source Packages/servlet/descargarNookSV.java
web/js/bdFilenook.sql
+2
-2
2 additions, 2 deletions
web/js/bdFilenook.sql
with
75 additions
and
51 deletions
Source Packages/conexionDB/documentoDB.java
+
34
−
45
View file @
5efa021b
...
...
@@ -12,6 +12,7 @@ import java.io.FileNotFoundException;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.PreparedStatement
;
...
...
@@ -99,15 +100,22 @@ public class documentoDB {
documento
.
setResumen
(
rs
.
getString
(
"resumen"
));
documento
.
setFechaCreacion
(
rs
.
getDate
(
"fechaCreacion"
));
documento
.
setFechaModificacion
(
rs
.
getDate
(
"fechaModificacion"
));
documento
.
setDocumento
(
rs
.
getBlob
(
"documento"
));
documentos
.
add
(
documento
);
InputStream
is
=
rs
.
getBinaryStream
(
"documento"
);
String
str
=
convert
(
is
);
new
File
(
"temp"
).
mkdir
();
File
file
=
new
File
(
"temp/"
+
documento
.
getNombre
());
FileOutputStream
outputStream
=
new
FileOutputStream
(
file
);
outputStream
.
write
(
str
.
getBytes
());
outputStream
.
close
();
InputStream
is
=
documento
.
getDocumento
().
getBinaryStream
();
String
ruta
=
"temp"
+
File
.
separator
+
idNook
;
new
File
(
ruta
).
mkdirs
();
FileOutputStream
os
=
new
FileOutputStream
(
ruta
+
File
.
separator
+
documento
.
getNombre
());
byte
[]
buffer
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
is
.
read
(
buffer
))
!=-
1
){
os
.
write
(
buffer
,
0
,
bytesRead
);
}
is
.
close
();
os
.
flush
();
os
.
close
();
}
rs
.
close
();
ps
.
close
();
...
...
@@ -119,17 +127,17 @@ public class documentoDB {
}
}
public
static
int
insertDocu
(
int
idNook
,
Part
documento
)
throws
IOException
{
public
static
double
borrarArchivo
(
String
nombre
,
int
idNook
)
{
ConnectionPool
pool
=
ConnectionPool
.
getInstance
();
Connection
connection
=
pool
.
getConnection
();
PreparedStatement
ps
=
null
;
String
consulta
=
"UPDATE Documento SET documento=? WHERE nook= ?"
;
String
consulta
=
"DELETE FROM Documento WHERE nombre = ? AND nook = ?"
;
try
{
ps
=
connection
.
prepareStatement
(
consulta
);
ps
.
setBlob
(
1
,
documento
.
getInputStream
()
);
ps
.
setString
(
1
,
nombre
);
ps
.
setInt
(
2
,
idNook
);
int
res
=
ps
.
executeUpdate
();
...
...
@@ -140,38 +148,20 @@ public class documentoDB {
e
.
printStackTrace
();
return
0
;
}
}
private
static
String
convert
(
InputStream
is
)
{
BufferedInputStream
bis
=
new
BufferedInputStream
(
is
);
ByteArrayOutputStream
buf
=
new
ByteArrayOutputStream
();
int
result
;
String
str
=
null
;
try
{
result
=
bis
.
read
();
while
(
result
!=
-
1
)
{
buf
.
write
((
byte
)
result
);
result
=
bis
.
read
();
}
str
=
buf
.
toString
(
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
str
;
}
public
static
double
borrarArchivo
(
String
nombre
,
int
idNook
)
{
public
static
int
insertDocu
(
int
idNook
,
Part
documento
)
throws
IOException
{
ConnectionPool
pool
=
ConnectionPool
.
getInstance
();
Connection
connection
=
pool
.
getConnection
();
PreparedStatement
ps
=
null
;
String
consulta
=
"DELETE FROM Documento WHERE nombre = ? AND nook = ?"
;
String
consulta
=
"UPDATE Documento SET documento=? WHERE nook= ?"
;
try
{
ps
=
connection
.
prepareStatement
(
consulta
);
ps
.
setString
(
1
,
nombre
);
ps
.
setBlob
(
1
,
documento
.
getInputStream
()
);
ps
.
setInt
(
2
,
idNook
);
int
res
=
ps
.
executeUpdate
();
...
...
@@ -182,6 +172,5 @@ public class documentoDB {
e
.
printStackTrace
();
return
0
;
}
}
}
This diff is collapsed.
Click to expand it.
Source Packages/servlet/descargarNookSV.java
+
39
−
4
View file @
5efa021b
...
...
@@ -6,12 +6,10 @@
package
servlet
;
import
conexionDB.documentoDB
;
import
java.io.BufferedInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.File
Out
putStream
;
import
java.io.File
In
putStream
;
import
java.io.IOException
;
import
java.io.
In
putStream
;
import
java.io.
Out
putStream
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.logging.Level
;
...
...
@@ -48,6 +46,43 @@ public class descargarNookSV extends HttpServlet {
String
usuario
=
(
String
)
session
.
getAttribute
(
"usuario"
);
int
nook
=
Integer
.
parseInt
(
request
.
getParameter
(
"idNook"
));
ArrayList
<
Documento
>
documentos
=
documentoDB
.
getFiles
(
nook
);
String
nombreArchivo
=
documentos
.
get
(
0
).
getNombre
();
// String rutaAplicacion = getServletContext().getRealPath("");
// String rutaDescarga = rutaAplicacion + File.separator + "temp";
String
ruta
=
"temp"
+
File
.
separator
+
nook
+
File
.
separator
+
nombreArchivo
;
File
file
=
new
File
(
ruta
);
OutputStream
outStream
=
null
;
FileInputStream
inputStream
=
null
;
System
.
out
.
println
(
file
.
getName
());
if
(
file
.
exists
()){
response
.
setContentType
(
"application/octet-stream"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
file
.
getName
()
+
"\""
);
try
{
outStream
=
response
.
getOutputStream
();
inputStream
=
new
FileInputStream
(
file
);
byte
[]
buffer
=
new
byte
[
1024
*
100
];
int
bytesRead
=
-
1
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))!=-
1
){
outStream
.
write
(
buffer
,
0
,
bytesRead
);
}
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
finally
{
if
(
inputStream
!=
null
)
{
inputStream
.
close
();
}
outStream
.
flush
();
if
(
outStream
!=
null
){
outStream
.
close
();
}
}
}
else
{
response
.
setContentType
(
"text/html"
);
response
.
getWriter
().
println
(
"<h3>File \"+ fileName +\" Is Not Present .....!</h3>"
);
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
...
...
This diff is collapsed.
Click to expand it.
web/js/bdFilenook.sql
+
2
−
2
View file @
5efa021b
...
...
@@ -17,7 +17,7 @@ CREATE TABLE Usuario(
clave
VARCHAR
(
15
)
NOT
NULL
,
correo
VARCHAR
(
80
)
NOT
NULL
,
valoracionMedia
NUMERIC
(
3
,
1
),
imagenPerfil
BLOB
,
imagenPerfil
BLOB
(
5
M
)
,
PRIMARY
KEY
(
nombreUsuario
)
);
...
...
@@ -60,7 +60,7 @@ CREATE TABLE Documento(
resumen
VARCHAR
(
400
),
fechaCreacion
DATE
,
fechaModificacion
DATE
,
documento
BLOB
,
documento
BLOB
(
16
M
)
,
PRIMARY
KEY
(
nook
,
nombre
),
CONSTRAINT
FK_DOCUMENTO
FOREIGN
KEY
(
nook
)
REFERENCES
Nook
(
idNook
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment