10 Replies - 15321 Views - Last Post: 30 December 2016 - 01:39 PM Rate Topic: -----

#1 o.sami   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-May 08

JDBC connection with MS SQL server 2005

Post icon  Posted 04 April 2009 - 01:48 PM

hey all,
i could n`t establish a connection between JDBC and MS SQL server 2005, i could n`t understand what driver is needed or how to install them, So i am facing a problem with driver and url, please help:(

thnx in advance,

This post has been edited by o.sami: 04 April 2009 - 01:50 PM

Is This A Good Question/Topic? 0
  • +

Replies To: JDBC connection with MS SQL server 2005

#2 Thura   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 25
  • Joined: 27-February 08

Re: JDBC connection with MS SQL server 2005

Posted 04 April 2009 - 02:52 PM

Have you installed the driver ?
If you did already, you need to add the library ....
In netbeans, it should be Project >> Properties >> Library >> Add library ...
or set the classpath manually on command line with the path to mysql jar file.
http://en.wikipedia....h_of_a_Jar_file
Was This Post Helpful? 0
  • +
  • -

#3 o.sami   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-May 08

Re: JDBC connection with MS SQL server 2005

Posted 04 April 2009 - 07:55 PM

View PostThura, on 4 Apr, 2009 - 01:52 PM, said:

Have you installed the driver ?
If you did already, you need to add the library ....
In netbeans, it should be Project >> Properties >> Library >> Add library ...
or set the classpath manually on command line with the path to mysql jar file.
http://en.wikipedia....h_of_a_Jar_file


thnx 4 ur reply,

i installed sqljdbc_2.0 (is that the right driver ?), and set the classpath, Now i don`t know what should be written while establishing a connection :

Class.forName("HERE");
String url = "AND HERE";

Note : am not using java beans
Was This Post Helpful? 0
  • +
  • -

#4 canty   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 41
  • Joined: 26-January 08

Re: JDBC connection with MS SQL server 2005

Posted 07 April 2009 - 07:35 PM

Here is my code :
package tugas.DataMining.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionManager {
	private Connection connection;
	private String driverClass;
	private String connectionURL;
	private String userID;

	private String userPassword;

	public ConnectionManager() {
		this.driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		this.connectionURL = "jdbc:sqlserver://localhost;database=AdventureWorks;integratedSecurity=true;";
		this.userID = "sa";
		this.userPassword = "sa";
	}

	public Connection getConnection() {
		return connection;
	}

	public void setConnection(Connection con) {
		this.connection = con;
	}

	public String getDriverClass() {
		return driverClass;
	}

	public void setDriverClass(String driverClass) {
		this.driverClass = driverClass;
	}

	public String getConnectionURL() {
		return connectionURL;
	}

	public void setConnectionURL(String connectionURL) {
		this.connectionURL = connectionURL;
	}

	public String getUserID() {
		return userID;
	}

	public void setUserID(String userID) {
		this.userID = userID;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	public void openConnection() {
		try {
			Class.forName(driverClass).newInstance();
			System.out.println("Open connection");
			setConnection(DriverManager.getConnection(getConnectionURL(), getUserID(),
					getUserPassword()));
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public void closeConnection() {

		try {
			System.out.print("  Closing Connection...\n");
			getConnection().close();

		} catch (SQLException e) {

			e.printStackTrace();

		}

	}

}



I'm use sqljdbc.jar
Was This Post Helpful? 1
  • +
  • -

#5 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: JDBC connection with MS SQL server 2005

Posted 07 April 2009 - 07:37 PM

Seems that your answer (fully documented and explained) comes directly from Indonesia :^: :D

This post has been edited by pbl: 07 April 2009 - 07:38 PM

Was This Post Helpful? 0
  • +
  • -

#6 canty   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 41
  • Joined: 26-January 08

Re: JDBC connection with MS SQL server 2005

Posted 08 April 2009 - 04:55 AM

View Postpbl, on 7 Apr, 2009 - 06:37 PM, said:

Seems that your answer (fully documented and explained) comes directly from Indonesia :^: :D


;)
Exactly :)
The code is from my homework :D
Was This Post Helpful? 1
  • +
  • -

#7 o.sami   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-May 08

Re: JDBC connection with MS SQL server 2005

Posted 09 April 2009 - 03:35 AM

its working now,
that was very helpful, thnx a lot

This post has been edited by o.sami: 09 April 2009 - 03:49 AM

Was This Post Helpful? 0
  • +
  • -

#8 canty   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 41
  • Joined: 26-January 08

Re: JDBC connection with MS SQL server 2005

Posted 09 April 2009 - 08:04 AM

View Posto.sami, on 9 Apr, 2009 - 02:35 AM, said:

its working now,
that was very helpful, thnx a lot


You're welcome :)
Was This Post Helpful? 0
  • +
  • -

#9 radhikarangu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-June 09

Re: JDBC connection with MS SQL server 2005

Posted 15 June 2009 - 03:47 AM

View Posto.sami, on 4 Apr, 2009 - 12:48 PM, said:

hey all,
i could n`t establish a connection between JDBC and MS SQL server 2005, i could n`t understand what driver is needed or how to install them, So i am facing a problem with driver and url, please help:(

thnx in advance,






View Posto.sami, on 4 Apr, 2009 - 12:48 PM, said:

hey all,
i could n`t establish a connection between JDBC and MS SQL server 2005, i could n`t understand what driver is needed or how to install them, So i am facing a problem with driver and url, please help:(

thnx in advance,

Hi,
I think it is use full for u....:)

String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=AdventureWorks;user=UserName;password=*****";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
Was This Post Helpful? 0
  • +
  • -

#10 zapp1   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 76
  • Joined: 07-December 16

Re: JDBC connection with MS SQL server 2005

Posted 30 December 2016 - 01:33 PM

I am interested can I connect jdbc(java) with dump (copy) of MS SQL SERVER database without installed ms sql server? At least for retrieving of data.
Was This Post Helpful? -1
  • +
  • -

#11 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12769
  • View blog
  • Posts: 45,954
  • Joined: 27-December 08

Re: JDBC connection with MS SQL server 2005

Posted 30 December 2016 - 01:39 PM

zapp1- Please do not necropost threads to ask questions. Please open your own threads instead.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1