Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100722394
DbConnectionAccess.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 2, 05:04
Size
2 KB
Mime Type
text/x-java
Expires
Tue, Feb 4, 05:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24018691
Attached To
R3229 Genome Privacy - SHCS App
DbConnectionAccess.java
View Options
package
database.access
;
import
java.io.File
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.bouncycastle.asn1.x9.X9ECParameters
;
import
org.bouncycastle.math.ec.ECPoint
;
import
database.Connector
;
public
class
DbConnectionAccess
implements
Connector
{
private
final
static
Logger
LOGGER
=
Logger
.
getLogger
(
DbConnectionAccess
.
class
.
getName
());
private
String
dbFilename
;
protected
Connection
connect
;
protected
PreparedStatement
preparedStmt
=
null
;
protected
ResultSet
resultSet
=
null
;
public
DbConnectionAccess
(
String
dbFilename
)
{
this
.
dbFilename
=
dbFilename
;
}
@Override
public
void
openConnection
()
{
try
{
Class
.
forName
(
"net.ucanaccess.jdbc.UcanaccessDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
null
,
e
);
System
.
exit
(-
1
);
}
File
filename
=
new
File
(
dbFilename
);
try
{
connect
=
DriverManager
.
getConnection
(
"jdbc:ucanaccess://"
+
filename
.
getAbsolutePath
());
}
catch
(
SQLException
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
null
,
e
);
}
}
@Override
public
void
closeConnection
()
{
try
{
if
(
connect
==
null
)
{
LOGGER
.
log
(
Level
.
WARNING
,
"Connection to "
+
dbFilename
+
" already closed."
);
}
if
(
resultSet
!=
null
)
{
resultSet
.
close
();
}
if
(
connect
!=
null
)
{
connect
.
close
();
}
}
catch
(
Exception
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
null
,
e
);
}
finally
{
connect
=
null
;
// LOGGER.log(Level.INFO, "Disconnected from " + ipAddr + "/" + database);
}
}
@Override
public
ECPoint
getPublicKey
(
int
ID_p
,
X9ECParameters
ecParams
)
throws
SQLException
{
preparedStmt
=
connect
.
prepareStatement
(
"SELECT value FROM cryptokeys WHERE ID_p=? AND isPublic=1"
);
preparedStmt
.
setInt
(
1
,
ID_p
);
resultSet
=
preparedStmt
.
executeQuery
();
if
(
resultSet
.
next
())
{
return
ecParams
.
getCurve
().
decodePoint
(
resultSet
.
getBytes
(
"value"
));
}
else
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Could not find public key for patient "
+
ID_p
);
return
null
;
}
}
}
Event Timeline
Log In to Comment