MySQL Jar works but MSSQL does not? - java

I don't use the Class.forName(abcde) for my MySQL-java-jdbc code. My code works properly.
All I did was drop the mysql.jar in my lib folder and the code worked.
But, for MSSQL, this does not work and I get the following error:
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433
I am using both sqljdbc.jar and sqljdbc4.jar, java 1.6 and MSSQL 2008.
Can you tell me how to find the cause for this problem ?

I think you've got the database connection URL wrong. There should be no microsoft within it. Try jdbc:sqlserver://localhost:1433 instead.
See also the MSDN documentation for the SQL Server JDBC driver.

Related

No suitable driver found for jdbc:db2 with db2jcc4.jar present in web-inf\lib

I am trying to run a simple java web app that connects to a back end DB2 database(IBM dashdb) to get retrieve some data.
I am getting a weird error message when I try to run this application on a ubuntu hosted tomcat 8.5.
I managed to get this application running on a tomcat v8 hosted on Windows.
The actual error message is:
No suitable driver found for jdbc:db2://yp-dashdb......
I don't really understand why this is happening because I have the db2jcc4. in my web-inf\lib folder.
I thought it was something wrong with the library so I created a separate Java app to simply connect and retrieve some data from the database. That one works just fine with the same library.
This is the code used to set up the connection (I trimmed out some of the details).
private Connection conn = null;
conn= DriverManager.getConnection("jdbc:db2://yp-dashdb...");
Keep in mind, that this exact same code works in a Standard Java app so the connection details work and there's no typo in the connection info.
Is there something obvious that I'm overlooking here?
After spending some time trying to figure this one out I find out the problem. My drivers were not being registered by DriverManager. The quick fix I found for this was to manually register it before trying to load the driver.
DriverManager.registerDriver(new com.ibm.db2.jcc.DB2Driver());
This has solved my issue. The way I found out about this was to print out all the registered drivers and print them out. Not the most elegant solution but it helped me find out what I'm missing.
/*
System.out.println("checking for drivers");
Enumeration<Driver> myDrivers = DriverManager.getDrivers();
System.out.println(myDrivers.hasMoreElements());
while(myDrivers.hasMoreElements()){
System.out.println(myDrivers.nextElement().toString());
}
*/
WEB-INF/lib is in your application. It might be so that tomcat needs this driver before your app is loaded? Try putting it into the tomcat's lib folder and restarting...
Here is another question on the same topic: Why must the JDBC driver be put in TOMCAT_HOME/lib folder?

How to set a MS Access DB (.mdb) in JasperSoft Studio (Eclipse)?

I have a .mdb database and I'm trying to design a report using JasperSoft Studio 6.3.0 (Eclipse plug-in).
In my Java Application I have used the UCanAccess JDBC Driver to build the connection as JDBC-ODBC Bridge is no longer supported in Java 8.
When creating the Data Adapter, I chose "Database JDBC Connection", and then, as UCanAccess is not in the default list of Drivers, I added the .jar file with the UCanAccess Driver.
Screenshot from the Classpath:
Then, I wrote the Driver Class in JDBC Driver (note: the standard action is to choose one of the drivers in the combobox, but as I had to add it manually, I read somewhere in the Internet that I must write it by myself).
Screenshot from the Driver setting:
When I test the connection, it will stay loading forever and will never end.
NOTE: the database has no user/pass. I successfully connected the database to my Java application (using the UCanAccess Driver); my problem is with the connection to the report.
What can I do? Any suggestions? Thanks!
I managed to solve my question by myself. I also had to add the four .jar in UCanAccess-x.x.x-bin>>lib to the Classpath (commons-lang, commons-logging, hsqldb, jackcess)

How could I connect my Eclipse IDE with the Oralce 11g in Windows 8?

I want my java program to handle Oracle SQL queries. For that, I have written the following code.
on running this code it shows the following errors.
I don't know how to connect my Eclipse IDE with the Oracle. How could I connect my Eclipse IDE to the Oracle and how to get rid of these errors? And I don't want to connect to any online oracle servers, I googled and get suggestions for connecting to online servers.
How could I connect my Oracle 11g with my Eclipse Kepler in Windows 8?
Please check below :
Driver version and DB version should be same.
Try login with sqlplus or some clients like Toad, SQL developer.
The number of connections allowed may exceeded, result in TNS listener error, that you may got minus one from read call error in stacktrace. If connections are exceeded kill inactive connections.
Try establishing connection like below
DriverManager.getConnection(DB_URL,USER,PASS);
Above exception your are getting when operating system has some internal environment problem.
I have got same problem with type 4 driver. But type 1 driver not giving this exception. So start using the type 1 oracle driver.
You can check the sid port in tnsnames.ora file which is in below location.
C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN\SAMPLE\tnsnames.ora

Android - connect to mssql database by jdbc

I'm trying to connect to live mssql database directly but I got the erro
"07-26 16:27:25.407: W/System.err(7136): java.sql.SQLException: Charset 0x0404E00000/MS950 is not supported by the JVM."
Here is the sample program I used by just changing the address/name/pw of the database.
https://github.com/alkber/AndroidByExample/tree/master/AndroidMSSQL2008
This problem is due to the JVM installed on your server.
It's caused by a limited language-only package (like US/English-only package).
You have to change the JVM to resolve this problem.
Reinstallaing JVM with complete language package should resolve your issue.
You shouldn't use jdbc for best coding and performance. Try to webservices.

Error while connecting to Oracle DSN using Java

I need to develop an application that connects to various DSN's using the Microsoft ODBC drivers. I have developed the application in Eclipse and it seems to work properly. The connection succeeds and I am able to view table data.
However when I export the project to a runnable jar file (using Eclipse) the functionality fails for Oracle. It is unable to establish connectivity with the Oracle connection string. It still works for SQL server but fails in case of Oracle. I'm unable to figure out the cause as the same ODBC drivers are being used for both Oracle and SQL-Server. More mystifying is that it runs properly on Eclipse. Since im using the ODBC drivers I don't believe the problem is because of an external jar file.
The driver is sun.jdbc.odbc.JdbcOdbcDriver and connection string is like jdbc:odbc:oratest;user=fell;password=pass.
I'm getting the following exception
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
Can you please help me figure what the problem might be?
Thanks in advance,
Fell
Create a System DSN.
java.sql.Connection cn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=java.sql.DriverManager.getConnection("jdbc:odbc:dsn_name","user","pass");
Check the classpath in the eclipse project

Categories

Resources