• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

basic SQL connection steps

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i don't know if this topic exists already or not, but i'll try my luck anyways. I am currently trying to make a connection with an sql server, and i have absolutely no idea what to do. I work with SQL Express 2008 R2 version. I downloaded the sqljdbc.jar and sqljdbc4.jar drivers from the internet. I put them in the folder where my project is, and added them as external jars to my project (in eclipse: project>properties>Java Build Path>add external jars) . Then i tried to run the following code:

import java.sql.*;
import java.util.*;

class JdbcTest1 {

public static void main(String args[]) {
try { // Step 1: Load the JDBC driver.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// Step 2: Establish the connection to the database.
String url = "jdbc:microsoft:sqlserver://localhost:1433/E"; //the port i use is 1433 and E is my database
Connection conn = DriverManager.getConnection(url,"sa","blabla"); //sa is the username and blabla is the password
} catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}

}

And i get the error: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433/E
And from now on i'm stuck. Been on a ton of forums and blogs and so on, tried a lot of solutions, none worked. Can someone please help me and tell me step-by-step what i have to do?
PS: I have already dealt with TCP/IP and Authentication Method problems, so I guess that everything comes from the code and the drivers
Thank you very much
 
Ranch Hand
Posts: 81
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the driver Jar file in the claspath ?

~Santhosh
 
Greenhorn
Posts: 24
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rus ,


Jar is not supported your current version sql express 2008 R2. Find right jar
 
Rus Corina
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I do. I'm thinking it's the code i put as the url or something. I don't know. And i'm using the sqldbc4.jar driver, since i've read that that is the proper driver for sql 2008
 
Rus Corina
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind, I found the problem
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rus Corina wrote:Nevermind, I found the problem


What was it?
 
Greenhorn
Posts: 2
Java ME MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i m also trying to connect ms sql 7 with servlet and i m always getting the errors....i do not know what type of jar files i needed and where i will get it from.....so please tell me how i will solve the problem if you already solve the problem......Reply me as soon as possible
 
Rus Corina
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne Boyarsky: the problem was that i did not use the proper driver name when i was trying to load it, and i was using the wrong url when trying to establish the connection with the server. Oh, and at the beginning i used a wrong driver. I used sqljdbc.jar instead of sqljdbc4.jar


Rohit kumar singh : I don't really know what servlet is, but i used the sqljdbc4.jar driver for the connection. You can get it here: http://www.microsoft.com/download/en/details.aspx?id=2505
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,
I'm very new to both Java and SQL and have just joined this forum (my very first forum membership ever) after having racked my brains out, searching and reading quite a bit of forums and blogs on how to connect to MS SQL Server 2008 R2 64 bit. I'm trying Rus' script as it seems fairly straightforward.
-I've done all the prep work with the jar files, both sqljdbc4.jar and sqljdbc.jar in Eclipse and made sure the port 1433 is in place.

import java.sql.*;

class conn2 {

public static void main(String args[]) {
try { // Step 1: Load the JDBC driver.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// Step 2: Establish the connection to the database.
String url = "jdbc:microsoft:sqlserver://localhost:1433/JAVADB"; //the port i use is 1433 and JAVADB is my database
Connection conn = DriverManager.getConnection(url,"SS",""); // I'm not using a password, would this be a problem??
} catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}


result I'm getting:
"Got an exception!
No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433/JAVADB"

-I noticed that my server name is "SS-THINK\SQLEXPRESS" but I can't use this name b/c it contains a single "\" which isn't accepted in Java language
-I've also set the authentication to using both SQL Server and Windows authentication

Thanks again all- I would truly appreciate any help out.

Sithi

 
reply
    Bookmark Topic Watch Topic
  • New Topic