I am new to Eclipse.
Currently developing a sample web application using primefaces 3.1 and glassfish 3.
I have created a oracle database connection under datasource explorer. I would like to know how to
integrate this with my web application, so that I could connect to database from my web application. I know that by creating context.xml and entering the following might be suffice for database access, but are there anyways to integrate database connection with my application? So that I do not need to hard code password in context.xml.
I have used Jdeveloper in the past and by creating a database connection corresponding datasource entries in xml are generated. So I was wondering something similar would be possible using Eclipse?
Any help is highly appreciated.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/SampleDB" auth="Container"
type="javax.sql.DataSource"
username="app" password="app"
driverClassName="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/sample"
maxActive="8" />
</Context>
I have found a solution to create datasource for glassfish.
I created a a JDBC Resource under GlassFish and pointed connection to my connection created under Date Source Explorer. It created a sun-resources.xml. I had to manually rename this to glassfish-resource.xml. By default there are no entry for password,so I had to manually add . When I ran my web application I was getting this error
java.sql.SQLException: Error in allocating a connection. Cause: No PasswordCredential found
So to resolve this error I added a property in JDBC Connection Pool in glassfish admin server. Now I could connect to Oracle database.
Not sure why I have to do two steps manually. Besides by default it creates sun-resources.xml. Perhaps someone could point out how to workaround these.
Thanks
Related
Trying to connect, using Hibernate 4.3, to SQL Server with Windows Authentication, i'm getting a:
"No Persistence provider for EntityManager named instanceTest"
I have loaded the sqljdbc_auth.dll library and im using this url:
jdbc:sqlserver://localhost:1433;databaseName=WIN_AUTHDB;integratedSecurity=true
The parameters which i am using to create the entity manager factory are:
properties.put("background-validation", "true");
properties.put("hibernate.c3p0.idle_test_period", "3600");
properties.put("hibernate.hbm2ddl.auto", "update");
properties.put("hibernate.max_fetch_depth", "3");
properties.put("hibernate.connection.driver_class", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
properties.put("hibernate.connection.url","jdbc:sqlserver://localhost:1433;databaseName=WIN_AUTHDB;integratedSecurity=true");
Im missing something? Maybe is the dll not loaded? The error is thrown at this line:
Persistence.createEntityManagerFactory("instanceTest", initProperties(properties));
The database is correctly configured, i have connected through Windows Authentication with the SQL Server Management. Also, in a previous test, i achieved to create a database using the driver without hibernate.
Thanks in advance.
Along those, add the below property
properties.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
Resolved!
Much more simple than I thought. When I was compiling the maven project, i was unintentionally deleting the persistence.xml file. Thats the reason because it never found the persistence provider at the war.
I have MVC app running fine in local. After updating to Azure, it started throwing the error:
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project.
I have checked if there is any difference between the local web.config and azure web.config. except the credentials, everything is same. And it read:
<add name="DBEntities"
connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;
provider=System.Data.SqlClient;
provider connection string="data source=xx;initial catalog=xx;persist security info=True;user id=xx;password=xx;MultipleActiveResultSets=True;application name=EntityFramework""
providerName="System.Data.EntityClient" />
I am using EF 6.1.3, MVC5
I ran into the same error message and managed to solve it with the help of this post here on StackOverflow.
In the Azure Management / Web Apps / [Your web app] / CONFIGURE / connection strings , make sure of 3 things :
The connection string has the same name as the connection string in your project.
The connection string Value contains all of the metadata as appears in the connection string in your project. Mine looks like this:
metadata=res://\*/Models.[MyModel].csdl|res://\*/Models.[MyModel].ssdl|res://\*/Models.[MyModel].msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:[myDBServer].database.windows.net,1433;Database=[myDB];User ID=[myDBUser]#[myDBServer];Password=[myPassword];Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
The third column (default set to SQL Database) is set to Custom
Found a simpler solution than adding all the stuff in the Azure connection string. I just changed the connection string name in Azure. It worked..
I had to deal with the same issue. The solution was
Connect to the website by FTP
Edit web.config
Add following connection string:
add name="NewDatabaseEntities" connectionString="metadata=res:///NewDatabase.csdl|res:///NewDatabase.ssdl|res://*/NewDatabase.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:your.database.windows.net,1433;initial catalog=your;integrated security=False;User Id=your;Password=your;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
Thanks Microsoft for poorly documentation of EntityFramework Database First on Azure.
You need to change this line metadata=res:///NewDatabase.csdl|res:///NewDatabase.ssdl|res://*/NewDatabase.msl;
to
metadata=res://*/;
I'm using the AWS Toolkit in Visual Studio 2013 to attempt to launch a new instance on Amazon RDS. I get through the wizard for creating the new instance and after clicking finish, there is a delay, and then a message appears saying:
Error launching DB instance: DB Security Groups can only be associated with VPC DB Instances using API version 2012-01-15 through 2012-09-17.
Launching different types of instances (SQL Server SE vs MySQL) doesn't seem to help, nor does selecting different versions of the platforms (SQL Server 2008 vs 2012). The only thing that gets it to go through is unchecking the box for "default" in the DB Security Groups area. However, I feel like something is going on here that shouldn't be happening.
Can anyone explain why this is happening and how I can resolve it other than by not setting a default security group? Thank you.
If you created your AWS account recently, you will be using a VPC by default.
It sounds like the API the plugin is trying to use hasn't been updated. The latest version is 1.5.6, and looking at the history it seems like some of these features were added in 1.5.0.
I finally solved it! Since I couldn't use the API that the VS 2013 plugin uses, I had to manually add my IP to the Security Group created for my Elastic Beanstalk.
Go to the console, ec2's security groups configuration
Find the one which description matches your Beanstalk (e.g.: Security Group created for Beanstalk Environment to give access to RDS instances)
Hit Inbound, Edit and add a new rule for All Traffic (I guess HTTP should be enough, but just in case).
In Source, select My IP and Save.
I'm new to Play framework. I'm trying to configure MySQL database as a datasource to be used with Play.
i have done following setting to connect mysql database to play..
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/phpmyadmin/index.php?db=formdemo&token=3882f545563c7df106e1daf21515e1b7#PMAURL:db=formdemo&server=1&target=db_structure.php&token=3882f545563c7df106e1daf21515e1b7"
but i am getting following configuration error.
play.api.Configuration$$anon$1: Configuration error[Cannot connect to
database [default]]
I am not able to connect my wamp localhost database to play.
How do I modify the configuration file to use a mysql database as opposed to an in-memory version. Do I need to setup an entirely separate DB or can I modify the db.default.url property?
I'm using Play! 2.1.
I have resolved with issue. Thank You for your guidance.
Few lines to Put.
dependency
"mysql" % "mysql-connector-java" % "5.1.18"
Conf
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/FORMDEMO?characterEncoding=UTF-8"
db.default.user=root
db.default.password=""
Follow the reference,
http://blog.knoldus.com/2013/01/28/play-framework-2-0-connectivity-with-mysql-in-scala/
Your url should be in this structure:
db.default.driver=com.mysql.jdbc.Driver
db.default.url="mysql://username:password#localhost/formdemo"
If you didn't set the default password, it is usually root with no password, like this:
db.default.url="mysql://username:#localhost/formdemo"
I have a requirement to display the database name on the screen that is connected by the web application (which is configured through the datasource on weblogic server with spring data xml having all the configurations) and also is there any way to switch from current database to different datasource (database server) while working/running on the web application (with user screen).
Thanks.
As far as I know, there is no straight-forward way to know this info. One way I can think of doing this is to parse the spring config XML file using an XML parser for the desired element - even that too will only give you the JNDI name of the datasource your app would be using. I hope you have a mechanism to determine which JDBC JNDI name maps to which database. If you don't have that information, you would have to use JMX (MBeans) to connect to the Weblogic environment to get that info.