Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Connection SQLServer 2005 with jdbc

Thread view: 
Benoît - 06 Jan 2006 18:42 GMT
Hi,
Here is my code :
-------------------
package bdd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class TestSQLServer {
    private String driver =
"com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private String server =
"jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=Base1;SelectMethod=cursor";
    private String login = "user1";
    private String mdp = "user1";

    public TestSQLServer(){

    }

    public void test(){
        try{
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(server,login,mdp);

            Statement instruction = conn.createStatement();
            ResultSet resultat = instruction.executeQuery("SELECT * FROM
personne");

            while(resultat.next()){
                System.out.println("-------------");
                System.out.println("Nom : "+resultat.getString("nom"));
                System.out.println("Prénom : "+resultat.getString("prenom"));
            }
        } catch(Exception e){
            System.out.println("Erreur de connexion : "+e);
            System.exit(-1);
        }
    }

    public static void main(String[] args) {
        TestSQLServer ts = new TestSQLServer();
        ts.test();

    }
}

------------------
And I've the following error message :
------------------
Error Trace in getConnection() : No suitable driver
Error: No active Connection
java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at bdd.Connect.getConnection(Connect.java:26)
    at bdd.Connect.displayDbProperties(Connect.java:43)
    at bdd.Connect.main(Connect.java:79)
------------------

I don't see...
Any idea?

Thanks
Aquila Deus - 07 Jan 2006 09:30 GMT
> Hi,
> Here is my code :
[quoted text clipped - 60 lines]
> I don't see...
> Any idea?

M$'s JDBC driver is unusable. Use jTDS.
Raymond DeCampo - 08 Jan 2006 03:59 GMT
> Hi,
> Here is my code :
[quoted text clipped - 9 lines]
>     private String driver =
> "com.microsoft.sqlserver.jdbc.SQLServerDriver";

To the best of my knowledge the driver is
com.microsoft.jdbc.sqlserver.SQLServerDriver.  Of course if that were
the problem you should get an exception on the Class.forName(driver) line.

>     private String server =
> "jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=Base1;SelectMethod=cursor";
[quoted text clipped - 44 lines]
>     at bdd.Connect.main(Connect.java:79)
> ------------------

HTH,
Ray

Signature

XML is the programmer's duct tape.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.