How do I install MSSQL driver in my project with Eclipse's maven? (m2e)? And also make it not conflict with Vaadin? When I install the MSSQL driver locally following these instructions, during the compile and runtime, it says "Could not find archetype from Vaadin-addons."
I have the code:
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://server;databaseName=dbname;user=username;password=password");
String sql = "Select * from Table1";
stmt = con.createStatement( );
rs = stmt.executeQuery(sql);
while (rs.next()){
contractorsList.addBean(new Contractor(rs.getString(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getString(6)));
}
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}finally{
try { con.close(); } catch (SQLException e) {}
try { rs.close(); } catch (SQLException e) {}
try { stmt.close(); } catch (SQLException e) {}
I'm getting the following error:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:450)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403)
at java.lang.Class.forName0(Native Method)
Which means that it can't find my driver, I think. So I'm following this tutorial on installing the MS SQL driver. I download the driver from microsoft and then I unzip it here:
C:\SQLDriver
In Eclipse, on my project folder, I right click > Debug As > Debug Configurations >
mvn install:install-file -Dfile=C:\SQLDriver\sqljdbc_4.0\enu\sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0.2206.100 -Dpackaging=jar
Then I add in the following in my POM
<properties>
<!–….other versions–>
<sqlserver.version>4.0.2206.100</sqlserver.version>
</properties>
...
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>${sqlserver.version}</version>
</dependency>
I get an error that it can't find my dependency, So I look up the question here, and I found out that I simply need to add sqljdbc4 to my classpath.
I have no idea what that means but google took me here So I attempt to follow the instructions.
In System Properties > Advanced > Environment Variable under Variables, I add the following:
I searched here and it looks like someone else asked the same question
I honestly don't know what people mean by add it to the classpath. Do they mean paste the jars in the same folder as the project? Either way, I just found a .classpath file in my project and added these:
How do I get maven to use this microsoft sql driver?
[Edit] When going to Libraries > Maven Dependencies, right click > build path > configure build path, I see this:
Which, when I click, it doesn't let me edit the path of that file. I'm not sure where to edit it.