Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Connection SQLServer 2005 with jdbc

Reply
Thread Tools

Connection SQLServer 2005 with jdbc

 
 
=?iso-8859-1?B?QmVub+50?=
Guest
Posts: n/a
 
      01-06-2006
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=cur sor";
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

 
Reply With Quote
 
 
 
 
Aquila Deus
Guest
Posts: n/a
 
      01-07-2006
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=cur sor";
> 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.

 
Reply With Quote
 
 
 
 
Raymond DeCampo
Guest
Posts: n/a
 
      01-08-2006
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=cur sor";
> 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.
 
Reply With Quote
 
SNK111 SNK111 is offline
Junior Member
Join Date: Apr 2010
Posts: 6
 
      06-14-2010
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
True JDBC (not odbc bridge) for MS VM? - SQLServer 2000 G Java 2 10-12-2008 12:38 AM
Do JRun4 JDBC drivers support Microsoft SQLServer 2005? Rich Carreiro Java 0 09-25-2007 07:11 PM
Upgrading ASP w/SQLserver 2000 to ASP.NET w/ SQLserver 2005 =?Utf-8?B?SmVmZnJleQ==?= ASP .Net 2 04-27-2007 03:33 PM
Invalid Select :[IBM][SQLServer JDBC Driver] mareluad Java 0 02-20-2006 10:08 AM
java.lang.ClassNotFoundException:com.microsoft.jdbc.sqlserver.SQLServerDriver zhao Java 3 07-16-2003 07:38 PM



Advertisments