User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: May 2008
Posts: 35
Reputation: alpe gulay is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
alpe gulay's Avatar
alpe gulay alpe gulay is offline Offline
Light Poster

can you see whtas wrong with this one!!

  #1  
May 15th, 2008
..'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
.,'Baby Pro'.,
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,461
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: can you see whtas wrong with this one!!

  #2  
May 15th, 2008
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.
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
Reply With Quote  
Join Date: May 2008
Posts: 35
Reputation: alpe gulay is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
alpe gulay's Avatar
alpe gulay alpe gulay is offline Offline
Light Poster

Re: can you see whtas wrong with this one!!

  #3  
May 15th, 2008
.,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...
.,'Baby Pro'.,
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
Reply With Quote  
Join Date: Dec 2007
Location: Greece
Posts: 560
Reputation: javaAddict will become famous soon enough javaAddict will become famous soon enough 
Rep Power: 3
Solved Threads: 64
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Pro

Re: can you see whtas wrong with this one!!

  #4  
May 15th, 2008
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
Last edited by javaAddict : May 15th, 2008 at 3:19 am.
I AM the 12th CYLON
Reply With Quote  
Join Date: May 2008
Posts: 35
Reputation: alpe gulay is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
alpe gulay's Avatar
alpe gulay alpe gulay is offline Offline
Light Poster

Re: can you see whtas wrong with this one!!

  #5  
May 15th, 2008
..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...
.,'Baby Pro'.,
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
Reply With Quote  
Join Date: Feb 2006
Posts: 1,461
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: can you see whtas wrong with this one!!

  #6  
May 15th, 2008
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
Reply With Quote  
Join Date: Feb 2006
Posts: 1,461
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: can you see whtas wrong with this one!!

  #7  
May 15th, 2008
Originally Posted by javaAddict View Post
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
Reply With Quote  
Join Date: May 2008
Posts: 35
Reputation: alpe gulay is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
alpe gulay's Avatar
alpe gulay alpe gulay is offline Offline
Light Poster

Re: can you see whtas wrong with this one!!

  #8  
May 15th, 2008
.,.tnx for all the concerns guys!!
I'll try my best to fix this out!
.,'Baby Pro'.,
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
Reply With Quote  
Join Date: Dec 2007
Location: Greece
Posts: 560
Reputation: javaAddict will become famous soon enough javaAddict will become famous soon enough 
Rep Power: 3
Solved Threads: 64
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Pro

Re: can you see whtas wrong with this one!!

  #9  
May 15th, 2008
Originally Posted by masijade View Post
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
Reply With Quote  
Join Date: May 2008
Posts: 35
Reputation: alpe gulay is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
alpe gulay's Avatar
alpe gulay alpe gulay is offline Offline
Light Poster

Re: can you see whtas wrong with this one!!

  #10  
May 15th, 2008
.,...I got it already guys!
I made some changes i my driver connection..!
so far it works now!!!
tnx for sharing mhe your knowledge guys!!
.,'Baby Pro'.,
what you are today!
it's because on what you did yesterday'
what you did today!
is what in future you will be...'
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Java Forum

All times are GMT -4. The time now is 12:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC