The driver string for connecting to MSSQL Server is "jdbc:jtds:sqlserver://localhost:1433/tempdb".
If you know, how to connect to any database through jdbc, just replace the driver string. Also put the driver jar in your classpath. The default username for MSSQL Server is "sa" and there is not password.
For more on how to connect to a db through Jdbc, you can find documentations on sun's site.
First try yourself and post whatever you have tried.
Thanks, But how to load the driver Class.forName("?")
I have tried "com.microsoft.mssqlserver.SQLServerDriver"
it says
Class NotDefFound com.microsoft.mssqlserver.SQLServerDriver
And about the classpath. It is first time when i am dealing with JDBC, what do you mean by saying putting driver .jar in classpath
> Thanks, But how to load the driver
> Class.forName("?")
> I have tried
> "com.microsoft.mssqlserver.SQLServerDriver"
> it says
> Class NotDefFound
> com.microsoft.mssqlserver.SQLServerDriver
> nd about the classpath. It is first time when i am
> dealing with JDBC, what do you mean by saying putting
> driver .jar in classpath
http://www.microsoft.com/downloads/details.aspx?familyid=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en
The driver you are trying to load is Microsoft provided JDBC driver for SQL server 2000. You can download it at the link mentioned above.
For instructions on how to set classpath and use the driver, read http://support.microsoft.com/kb/313100
If you want to use the jTds driver, you need to add it to the classpath and use the appropriate driver class and connection url. Refer to the jTds documentation for that.
Thanks, aniseed.
I have downloaded the driver and installed it. Also added msbase.jar, msutil.jar and mssqlserver.jar to the classpath. But there is some another error. Here is my code
/**
* @(#)Test.java
*
*
* @author
* @version 1.00 2007/6/29
*/
import java.sql.*;
public class Test {
static String jdbcDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
static String url = "jdbc:microsoft:sqlserver://universal:1433;DatabaseName=borej;User=sa;Password=";
static String SQLCreate =
"CREATE TABLE CONTACT_INFO ("+
"CONTACT_ID INTEGER NOT NULL PRIMARY KEY,"+
"FIRST_NAME VARCHAR(20) NOT NULL,"+
"MI CHAR(1) NULL,"+
"LAST_NAME VARCHAR(30) NOT NULL,"+
"STREET VARCHAR(50) NOT NULL,"+
"CITY VARCHAR(30) NOT NULL,"+
"STATE CHAR(2) NOT NULL,"+
"ZIP VARCHAR(10) NOT NULL"+
");";
public Test() {
try{
Class.forName(jdbcDriver);
}
catch(ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public void execute(String SQLCommand){
try{
Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
stmt.execute(SQLCommand);
con.close();
}
catch(SQLException e){
System.err.println(e.getMessage());
}
}
public static void main(String[] args) {
Test test = new Test();
test.execute(SQLCreate);
}
}
ERROR is:
Couldn't establish socket.
Please tell me what is my fault, what I did wrong.
Hi, guys.
I have not found solution yet.
When I am trying with JTDS
Class.forName("net.sourceforge.jdbc.jtds.Driver")
DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/master;user=sa;password=") ;
I am getting IONetwork exception connection: Connection refused.
When I am trying on JDBC SQL Driver 2000
Class.forName("com.microsoft.jdbc.SQLServerDriver")
DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433","sa",""):
I am getting exception: Error establishing socket. Anyone please help me.
Can u check ur connectionUrl anf Class.forName
try this out
class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;User=abc;Password=xyz")
n have to set classpath for SQLjdbc driver?
try the help web page tht is thr where u have installed/downloaded SQl JDBC drivers........
Good Luck...