•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 428,064 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,463 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 385 | Replies: 9
![]() |
..'I made a simple program in which will connect to ms sql...
then, after running the codes something is error!
can you help me to solve this out...
here is my code:
import java.sql.*;
public class connect_sql {
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433","ben","");
if(!con.isClosed())
System.out.println("Successfully connected to MSSQL server...");
}
catch(Exception e)
{
System.err.println("Exception: " + e.getMessage());
}
finally {
try
{
if(con != null)
con.close();
}
catch(SQLException e) {}
}
}
}
and here is the error msg:
Exception: com.microsoft.jdbc.sqlserver.SQLServerDriver
what should I do so that I can connect to sql...
can you pls help me here...
-tnx
then, after running the codes something is error!
can you help me to solve this out...
here is my code:
import java.sql.*;
public class connect_sql {
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433","ben","");
if(!con.isClosed())
System.out.println("Successfully connected to MSSQL server...");
}
catch(Exception e)
{
System.err.println("Exception: " + e.getMessage());
}
finally {
try
{
if(con != null)
con.close();
}
catch(SQLException e) {}
}
}
}
and here is the error msg:
Exception: com.microsoft.jdbc.sqlserver.SQLServerDriver
what should I do so that I can connect to sql...
can you pls help me here...
-tnx
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
Add an e.printStackTrace() to your catch block and post the entire error message.
It's probably that you don't have the sqlserver driver jarfile on your classpath.
It's probably that you don't have the sqlserver driver jarfile on your classpath.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
.,I tried to put that..then this error occurs
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at JCustomer.main(JCustomer.java:10)
Exception: com.microsoft.jdbc.sqlserver.SQLServerDriver
.,may I know whats the problem with this one...
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at JCustomer.main(JCustomer.java:10)
Exception: com.microsoft.jdbc.sqlserver.SQLServerDriver
.,may I know whats the problem with this one...
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
Have you included this mysql-connector-java-5.0.7-bin.jar jar file?
If not use the above first and if it doesn't work try the below
I think that the problem is with value you use for:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
At first try to write: e.printStackTrace(); inside the catch(). You will get a better view of the exception. I think that the problem is with the driver you are using inside the Class.forName() method,
try this: com.mysql.jdbc.Driver.
and this: jdbc:mysql://localhost:1433/nameOfTheDB
If not use the above first and if it doesn't work try the below
I think that the problem is with value you use for:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
At first try to write: e.printStackTrace(); inside the catch(). You will get a better view of the exception. I think that the problem is with the driver you are using inside the Class.forName() method,
try this: com.mysql.jdbc.Driver.
and this: jdbc:mysql://localhost:1433/nameOfTheDB
Last edited by javaAddict : May 15th, 2008 at 3:19 am.
I AM the 12th CYLON
..I am using ms sql server,then is it necessary to put these
mysql-connector-java-5.0.7-bin.jar jar...
I thought mssql is difference than mysql...
well, I tried it also but still it doesnt connect in the database...
mysql-connector-java-5.0.7-bin.jar jar...
I thought mssql is difference than mysql...
well, I tried it also but still it doesnt connect in the database...
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
No, not the mysql connector jarfile, the sqlserver connector jarfile. That error means that you don't have it included on your classpath. Add it to your classpath.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
•
•
Have you included this mysql-connector-java-5.0.7-bin.jar jar file?
He's not using MySQL.
•
•
•
•
If not use the above first and if it doesn't work try the below
I think that the problem is with value you use for:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
That is correct for MS SQL Server.
•
•
•
•
At first try to write: e.printStackTrace(); inside the catch(). You will get a better view of the exception.
He just did that.
•
•
•
•
I think that the problem is with the driver you are using inside the Class.forName() method,
No, it's only that he doesn't have the driver on the classpath.
•
•
•
•
try this: com.mysql.jdbc.Driver.
and this: jdbc:mysql://localhost:1433/nameOfTheDB
That would work if he were using MySQL, and it were running on the port 1433.
Sorry, don't mean to be mean, but that entire post seems to be entirely offbase.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
•
•
He's not using MySQL.
That is correct for MS SQL Server.
He just did that.
No, it's only that he doesn't have the driver on the classpath.
That would work if he were using MySQL, and it were running on the port 1433.
Sorry, don't mean to be mean, but that entire post seems to be entirely offbase.
I didn't mean that he should take exactly this: mysql-connector-java-5.0.7-bin.jar. This is the jar I am using. I meant that he should take whatever he has installed in his computer. As far the port I used what he was using in his mail.
And I told him first to use the jar file and then if it didn't work to change the driver.
As far as my post was being little off was because by the time it took me to write it, you guys have already posted two threads before I submit.
And I don't think you were mean. Your comments said what needed to be said and nothing more.
Last edited by javaAddict : May 15th, 2008 at 4:48 am.
I AM the 12th CYLON
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Java Forum
- Previous Thread: Problem with methods and writing to file
- Next Thread: Creating Hover Effect for JButton



Linear Mode