Connection SQLServer 2005 with jdbc

Discussion in 'Java' started by =?iso-8859-1?B?QmVub+50?=, Jan 6, 2006.

  1. 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
     
    =?iso-8859-1?B?QmVub+50?=, Jan 6, 2006
    #1
    1. Advertisements

  2. =?iso-8859-1?B?QmVub+50?=

    Aquila Deus Guest

    M$'s JDBC driver is unusable. Use jTDS.
     
    Aquila Deus, Jan 7, 2006
    #2
    1. Advertisements

  3. 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.
    HTH,
    Ray
     
    Raymond DeCampo, Jan 8, 2006
    #3
  4. =?iso-8859-1?B?QmVub+50?=

    SNK111

    Joined:
    Apr 6, 2010
    Messages:
    6
    Likes Received:
    0
    HOW TO: SQL in JAVA

    Check this article ( shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html ) for details on how to connect to SQL Server database from Java database applications. It also describes how to pass embedded SQL queries (SELECT, INSERT, UPDATE, DELETE), calling stored procedures, pass parameters etc.
     
    SNK111, Jun 14, 2010
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.