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. Advertising

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

    Aquila Deus Guest

    Benoît wrote:
    > 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?
    >


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

  3. Benoît wrote:
    > 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";


    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";
    > 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)
    > ------------------
    >


    HTH,
    Ray

    --
    XML is the programmer's duct tape.
     
    Raymond DeCampo, Jan 8, 2006
    #3
  4. =?iso-8859-1?B?QmVub+50?=

    SNK111

    Joined:
    Apr 6, 2010
    Messages:
    6
    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zhao
    Replies:
    3
    Views:
    3,271
    Roedy Green
    Jul 16, 2003
  2. mareluad
    Replies:
    0
    Views:
    1,934
    mareluad
    Feb 20, 2006
  3. =?Utf-8?B?SmVmZnJleQ==?=

    Upgrading ASP w/SQLserver 2000 to ASP.NET w/ SQLserver 2005

    =?Utf-8?B?SmVmZnJleQ==?=, Apr 6, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    482
    sloan
    Apr 27, 2007
  4. Rich Carreiro
    Replies:
    0
    Views:
    367
    Rich Carreiro
    Sep 25, 2007
  5. G
    Replies:
    2
    Views:
    424
    Arne Vajhøj
    Oct 12, 2008
Loading...

Share This Page