Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vospacebackend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sara Bertocco
vospacebackend
Commits
7226ba27
Commit
7226ba27
authored
8 years ago
by
Sara Bertocco
Browse files
Options
Downloads
Patches
Plain Diff
New working version after Victoria trip - DB connection management
parent
f7c160f7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/it/inaf/oats/vospacebackend/implementation/DBConnectionMng.java
+72
-0
72 additions, 0 deletions
...f/oats/vospacebackend/implementation/DBConnectionMng.java
with
72 additions
and
0 deletions
src/main/java/it/inaf/oats/vospacebackend/implementation/DBConnectionMng.java
0 → 100644
+
72
−
0
View file @
7226ba27
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
it.inaf.oats.vospacebackend.implementation
;
import
com.mysql.jdbc.jdbc2.optional.MysqlDataSource
;
import
it.inaf.oats.vospacebackend.exceptions.ExceptionMessage
;
import
it.inaf.oats.vospacebackend.exceptions.VOSpaceBackendException
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
javax.naming.Context
;
import
javax.naming.InitialContext
;
import
javax.naming.NamingException
;
import
javax.sql.DataSource
;
import
org.apache.log4j.Logger
;
/**
*
* @author bertocco
*/
public
class
DBConnectionMng
{
private
static
final
Logger
log
=
Logger
.
getLogger
(
DBConnectionMng
.
class
);
public
static
Connection
getDBConnection
()
throws
SQLException
,
VOSpaceBackendException
{
DataSource
ds
=
getDataSource
();
Connection
dbConnection
=
ds
.
getConnection
();
return
dbConnection
;
}
public
static
DataSource
getDataSource
()
{
DataSource
ds
=
null
;
try
{
Context
initContext
=
new
InitialContext
();
Context
envContext
=
(
Context
)
initContext
.
lookup
(
"java:comp/env"
);
String
vosNodesDataSourceName
=
"jdbc/cadctest"
;
ds
=
(
DataSource
)
envContext
.
lookup
(
vosNodesDataSourceName
);
}
catch
(
NamingException
ex
)
{
log
.
fatal
(
ex
);
ds
=
null
;
}
return
ds
;
}
/**
* Providing a data source.
*/
/*
protected DataSource getDataSource() {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setDatabaseName("cadctest");
dataSource.setUser("oatsops");
dataSource.setPassword("Peper0ne");
dataSource.setServerName("localhost");
return dataSource;
}
*/
}
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