Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 10th, 2003, 09:55 AM
Ahmad Ahmad is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 1 Ahmad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Connecting Java with sql server

Hi

I am working on sql server 2000 , but i can not connect it with my java application. could any one help me in this regard.

An simple example or demo , of how to connect sql database with java applet would be wonderful.

Thank you

Reply With Quote
  #2  
Old July 14th, 2003, 08:43 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Ahmad,

It's not as hard as it sounds... I haven't interfaced Java w/ SQL server, but JDBC with any database server shouldn't be a tough task...

Read Sun's tutorial on JDBC.

HTH!
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old January 22nd, 2004, 10:49 AM
ramses04 ramses04 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 1 ramses04 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Hola!

Que tal!

Encontre algo similar a lo que buscas en la siguiente direccion, espero te sea de gran utilidad.

Articulo java-sql server

Saludos!.
Andres

Reply With Quote
  #4  
Old March 16th, 2004, 04:51 AM
hmtrungjava hmtrungjava is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 hmtrungjava User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up You can use following way!

This is fuction to Open a connection to SQL server (and Client) that I do completed! You can see it. Good luck to you!
-----------------------------------------------------
private boolean openConnection(String strServerIPAddress, String strDatabaseName, String strUserName, String strPassword) {
//String connect to SQL server
String url = "jdbc:microsoft:sqlserver://" + strServerIPAddress + ":1433" +
";DatabaseName=" + strDatabaseName;

try
{
//Loading the driver...
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
}
catch( java.lang.ClassNotFoundException e )
{
return false;
}

try
{
//Buiding a Connection
m_Conn = DriverManager.getConnection(url, strUserName, strPassword);
if(m_Conn == null )
return false;
}
catch( java.sql.SQLException e )
{
switch( e.getErrorCode() )
{
//...
return false;
}
}
return true;
}

Reply With Quote
  #5  
Old April 23rd, 2004, 01:59 PM
frigate frigate is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 frigate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Jdbc

I've tried to connect to my SQL Server 2k (local) machine to no avail.
Even the source code from Sun doesn't work. I've used Microsoft's and
Datadirect's JDBC driver. Everything compiles successfully but throws
these errors at runtime:

(Datadirect JDBC driver)
ClassNotFoundException: com.ddtek.jdbc.sqlserver.SQLServerDriver
SQLException: No suitable driver

(Microsoft JDBC driver)
ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
SQLException: No suitable driver



This is the modified sample code from Sun Java website:


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

public class CreateNewTable {
public static void main(String [] args) {
String url = "jdbc:microsoft:sqlserver://(local):1433";
Connection con;
Statement stmt;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url);
stmt = con.createStatement();

...

Reply With Quote
  #6  
Old April 3rd, 2009, 07:56 AM
sathya_k_83 sathya_k_83 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 1 sathya_k_83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 35 sec
Reputation Power: 0
Exclamation Re

Hi

Chanage the below from
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

to
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

then load the jdbc driver for sql server from the below url.


www . microsoft.com/downloads/thankyou.aspx?familyId=99b21b65-e98f-4a61-b811-19912601fdc9&displayLang=en

The above url will download a html file.
On clicking the html will help to downlad an zip file

Unzipping the file will give a jar file of the SQL Server JDBC.

You have place the jar file in the build path.



url ="jdbc:sqlserver://localhost:1433"

version: SQL Server 2008

But i get the below exception.


com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".



Quote:
Originally Posted by frigate
I've tried to connect to my SQL Server 2k (local) machine to no avail.
Even the source code from Sun doesn't work. I've used Microsoft's and
Datadirect's JDBC driver. Everything compiles successfully but throws
these errors at runtime:

(Datadirect JDBC driver)
ClassNotFoundException: com.ddtek.jdbc.sqlserver.SQLServerDriver
SQLException: No suitable driver

(Microsoft JDBC driver)
ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
SQLException: No suitable driver



This is the modified sample code from Sun Java website:


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

public class CreateNewTable {
public static void main(String [] args) {
String url = "jdbc:microsoft:sqlserver://(local):1433";
Connection con;
Statement stmt;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url);
stmt = con.createStatement();

...

Reply With Quote
  #7  
Old April 2nd, 2010, 03:01 AM
SNK111 SNK111 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2010
Posts: 14 SNK111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 4 m 30 sec
Reputation Power: 0
Connect from Java to sql server, pass sql queries, parameters etc

Check this link EMBEDDING SQL IN JAVA for details on how to connect to SQL server database from Java database applications as well as C#.NET database applications. It also describes how to pass embedded SQL queries, calling stored procedures, pass parameter etc.

Shahriar Nour Khondokar Shahriar Nour Khondokar[/URL]

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Connecting Java with sql server


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap