Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
6 replies
Subscribers
4 subscribers
Views
2496 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
Plug-Ins
Servlets - DB connect
sandeepg138
over 7 years ago
Hello All,
I am trying to insert a data in db when calling the servlet, it is working fine when in the code i use the connection string of mysql.
But it is not connecting to db, when using the datasource defined in the admin console eg: jdbc/test
Please let me know if the below code used is correct:
connection string
private Connection getConnection() {
Connection connection = null;
try {
Context context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("java:comp/env/jdbc/test");
connection = dataSource.getConnection();
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
Regards,
Sandeep
OriginalPostID-253947
Discussion posts and replies are publicly visible
0
ravinderl352
over 7 years ago
Update your context.loop to : jdbc/test
DataSource dataSource = (DataSource) context.lookup("jdbc/test");
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
ravinderl352
over 7 years ago
What is the error are you getting and what is the name of the datasource name defined in your environment ?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sandeepg138
over 7 years ago
the error we are seeing in JBOSS server log is Unable to find the datasource jdbc/test.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
ravinderl352
over 7 years ago
Looks like your not using right/correct data source name. Can you attach the data source settings screen shot from admin console ?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sandeepg138
over 7 years ago
datasource name is correct jdbc/test, as for same we are able to insert data throughprocess
So do we need to use this DataSource dataSource = (DataSource) context.lookup("jdbc/test");
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
ravinderl352
over 7 years ago
Hey Sandeep, If you want to use data source in servlets/outside Appian, you will have to create the data source in the Jboss. I don't think the data source you have created in Appian admin console can be used in servlet.
You can replicate this issue while defining the DS in appian-ds.xml/through Jboss admin console and then you can verify your servlet code.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel