Add dll to jee maven project [duplicate] - java

This question already has answers here:
Can I connect to SQL Server using Windows Authentication from Java EE webapp?
(5 answers)
Closed 4 years ago.
I am working in a jee maven project that needs to make a JDBC connection to SqlServer, using windows authentication.
To achieve that, I need to have the "sqljdbc_auth.dll" in my java.library.path .
I tried multiple solutions, none of them worked:
maven_surefire_plugin to modify the property path.
System.setProperty("java.library.path", "..."): this changed the property, but the connection didn't succeed telling me that the driver isn't configured for integratedSecurity connection.
Add the dll to a lib folder in Web_Inf & set the "Native Library_Path" of the maven dependency sqljdbc.
Add the dll to the bin folder in the "wildfly" server: gave me an exception: Exception Access Violation (fatal)
I appreciate any help, thank's in advance.

Adding .dll (which is windows-specific library) to JEE application (deployed on application server, usually running on linux platform) sound like a bad idea.
In your case, I believe that solution is much simpler: try to add integratedSecurity=true to your JDBC string, so it would like like this:
String url ="jdbc:sqlserver://localhost\sqlexpress;databaseName=myDatabase;integratedSecurity=true";
If this won't help, maybe consider using jTDS instead of regular driver from Microsoft - from my experience, it works much better.

Try adding below to your JDBC string:
Integrated Security=SSPI
The SSPI allows an application to use any of the available security packages on a system without changing the interface to use security services

Related

is tomEE aware of maven dependency? [duplicate]

This question already has answers here:
Where to put 3rd party libs when using Maven with Tomcat?
(2 answers)
Closed 3 years ago.
I am trying to use postgresql driver with tomcat.
but when i run tomcat I am getting FileNotFound exception(Class.forName("org.postgresql.Driver")).
Is tomEE aware of maven dependency.
how can I overcome it
No. Maven not involved after Tomcat/TomEE deployment
No, TomEE does not know about Maven or your POM.
As commented by Andreas, your Maven-driven web-app project will produce a WAR file or EAR file. That file contains any dependencies you may have configured in your POM.
For deployment, you will be moving that WAR or EAR file to the TomEE server. At that point there is no more Maven involvement.
These comments above apply to your eventual deployment for production. While in development, you may be using an IDE such as IntelliJ/NetBeans/Eclipse that can call upon an external web container such as Tomcat or TomEE to run and debug your web app. Maven settings may be involved in that special case, as part of hooking up your IDE to the external web container. Even in this special case, Tomcat/TomEE is not aware of Maven having possibly participated in its launching or configuration.
JDBC drivers are special
Furthermore, deploying a JDBC driver to Tomcat, TomEE, or other Jakarta Servlet container is a complicated matter because of classloader issues and the JDBC driver registration process. Generally, you should not be bundling a JDBC driver within your WAR/EAR.
Search Stack Overflow to learn more. Remember that TomEE is built on Apache Tomcat, so most anything you read about Tomcat applies.
See:
Where to put 3rd party libs when using Maven with Tomcat?
To prevent a memory leak, the JDBC Driver has been forcibly unregistered
How should I connect to JDBC database / datasource in a servlet based application?
By the way, in modern Java with its JDBC driver registration feature (DriverManager), you no longer need to call Class.forName. That call is now legacy.
DataSource
Tip: Learn to use a DataSource implementation provided by your driver. Regarding Postgres, if using the JDBC driver from jdbc.postgresql.org, see this chapter.
PGSimpleDataSource pgDataSource = new PGSimpleDataSource();
pgDataSource.setDataSourceName("Acme Corp invoicing database");
pgDataSource.setServerName("localhost");
pgDataSource.setDatabaseName("test");
pgDataSource.setUser("testuser");
pgDataSource.setPassword("testpassword");
DataSource dataSource = pgDataSource ; // Perhaps save as an "attribute" on your web app's "context".
Ask the data source for a Connection object when needing to talk to the database. Usually best to use try-with-resources syntax.
try
(
Connection conn = dataSource.getConnection() ;
)
{
… do your database work
}
Later you can learn to configure this DataSource info externally, outside your code base. That configuration is done through JNDI and a naming server such as the LDAP-style server built into Tomcat.

Birt: how to deploy a report in production?

I have just prepared a report with bird using eclipse plugin. It works.
Now I have deployed a birt 4.4 viwer on a Tomcat7. It works.
Now I put my report.rptdesign file insider birt folder under webapps in tomcat.
It does not work.
Obviously because:
the jdbc driver is encoded in report with full path that is obviously different from eclipse to tomcat;
birt needs a "org.eclipse.datatools_workspacepath" configured in tomcat (why????)
even if I configure above variable it complains about missing:
java.lang.NoClassDefFoundError: org/eclipse/datatools/enablement/ibm/util/ClientUtil
Yes I have used standard jdbc source (not "for query builder" one).
I would like to ask stack overflow why is so bloody complicated (and not documented) putting in production a simple report that uses a mysql jdbc jar.
Can you help me?
Thanks,
Mario
Well I don't understand all the question but I use birt with glassfish and jboss, you need to configure a JDBC in your server (I suppose you already have done that), then you have to change your Datasources erase all and use a JNDI URL with the name of your JDBC for example, if you create a datasource JDBC/test this is the JNDI url.
For the workspacepath I think this can be solved changing something in the birt war, go to META-INF and open the web.xml, then change this properties for another folders that have sufficient access permissions:
<param-name>BIRT_VIEWER_WORKING_FOLDER</param-name>
<param-name>BIRT_VIEWER_DOCUMENT_FOLDER</param-name>
<param-name>BIRT_VIEWER_IMAGE_DIR</param-name>
<param-name>BIRT_VIEWER_LOG_DIR</param-name>

JDBC and Sql Server 2008 Connectivity

I am accessing an SQL server 2008 Database through JDBC4.0. the problem is I can access my DB just when my glassfish server is restarted, it run the code normally but once, if i make any changes into the code i have to restart the glassfish server otherwise it generate the following error.
WARNING: Failed to load the sqljdbc_auth.dll cause : Native Library C:\Windows\System32\sqljdbc_auth.dll already loaded in another classloader
Kindly guide me what should i do to solve this problem i am using Eclipse editor. and my code is
String url = "jdbc:sqlserver://localhost;databaseName=ProductDB; integratedSecurity=true;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
con = DriverManager.getConnection(url);
System.out.println("Connected");
If you have a data source correctly defined in GlassFish you should be able to simply re-deploy your application in order to see changes to .java files (you can even use hot deploy although my experience with that has been less than great). XML files shouldn't even need a redeploy.
Update: I see from your edit you are loading the driver etc manually. I suggest you let GlassFish manage the data source and use resource injection to acquire a connection.
Edit: Re-reading your question properly... you don't need the sqljdbc_quth.dll library if you are using sql authentication but it will speeds up authentication with the sql server. I tried it out with one of our products but it didn't make any noticeable difference so I've not bothered since.
If you do any changes in xml or .java file definitely you have to restart.
If you use re loadable resource-bundle to read properties file its ok.
Updated :
Just go to Project in top bar than check "Build Automatically". It will stop auto building the project and saves your precious time.

How to access the jdbc driver from an online applet

My applet queries a mysql database, so I included the connector J jar in the eclipse project libraries and my applet runs fine in eclipse, but when i put it on the website, I get an error about that jdbc driver. When I made the jar of my project from eclipse, I don't think that the jdbc driver was included in the jar, so how would I access the jar? Should I put the jdbc jar inside my project jar, or have my project jar access the driver stored in its own jar.
Right now, I am using
<applet code="test.class" archive="math.jar" width=830 height=600 ></applet>
This isn't a good idea. You don't want an applet to access a database directly. You'll have to expose that port on the public Internet - not a good idea.
A better thought would be to put a servlet in between the applet and the database. Let the applet make the request to the servlet. It can deal with security, validation, binding, accessing the database, and marshalling the response.
Either put all classes from the jdbc.jar into "math.jar", or list it in the archive attribute: archive="math.jar,jdbc.jar".

MSSQL JDBC on unix

I am trying to integrate a web tool we have with a sql server database using Integrated Security. I have been looking around trying to find a unix version of the sqljdbc4.jar however I cannot seem to find one with .so files only .dll's.
Does anyone know where I can get a version with the .so files required or another way to use integrated security?
Currently my application is failing to connect with
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication
and I can see
WARNING: Failed to load the sqljdbc_auth.dll
earlier in the logs.
Using version 2.5 of mssqljdbc.
According to these docs, beginning with MSSQL JDBC Driver 4.0, you should be able to specify authenticationScheme=JavaKerberos to use the pure Java Kerberos implementation that doesn't need sqljdbc_auth.dll.
Note, I haven't tried this.
I know its late but for anyone searching this, try the following:
put the sqljdbc_auth.dll in your resource folder then add the following code
ClassLoader classLoader = TestDBConnection.class.getClassLoader();
File file = new File(classLoader.getResource("sqljdbc_auth.dll").getFile());
System.setProperty("java.library.path", file.getParent());

Categories

Resources