Total members 11894 |It is currently Sat Nov 23, 2024 9:21 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Connecting to SQLServer 2000 take from me 2 days until i discovered the problem,
I tried all the solutions on the net until i installed the Service Pack 3,
In fact the TCP server of SQL-Server 2000 was not working . u can check that using :
Code:
Telnet  localhost portnumber

in the command line

But after installation of Service pack3 finally TCP server work fine and i connected to the Database Server,So the first thing to do is to check the TCP server. Second if it not working try to install Service pack3 from Microsoft.

Here is the code to Open A connection to SQL-server 2000 using Microsoft JDBC
java code
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("Driver Exits !!!");

connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://computer_name:port","username","password");

} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
catch (SQLException ex) {
ex.printStackTrace();
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Thanks for Code

as JDK1.6 no need for Class.forName(..etc)


Author:
Newbie
User avatar Posts: 17
Have thanks: 0 time

Xline wrote:
Thanks for Code

as JDK1.6 no need for Class.forName(..etc)


But , I think we may need Class.forName to specify the Driver you are using :?: . For Example

For Mysql:
Code:
Class.forName("com.mysql.jdbc.Driver").newInstance();

For PostGrelsql :
Code:
Class.forName("org.postgresql.Driver").newInstance();


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

This Code learn you how to connect your java application with sql server using JDBC-ODBC:

Code for Database Connection in Java

java code
Import java.sql.*;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:WSD");
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("SELECT * from student");
statement.execute("insert into student values (1,12)");
}
catch (Exception e)
{
}


Notes :
WSD is the name of the connection name you made in the ODBC.
Line 7 is used if you want to execute a select statement and you can read data using string return = java code
result.getString("here you put the columns index you want to get its value");   // 1 as an example

To move the pointer of reading you write result.next();
Don't forget the import statement.
Line 8 is used to execute any non- select statement.
To make a connection name called "mydb" do the followings:
Control Panel -> Administrative Tools - >Data Sources (ODBC) -> add
Search for SQL Server then - > choose it and then click Finish
Write a name, description and name of your server - > name is -- and server is your SQL Server Name Then click next, then another next.
Change the default database to -- and choose your one , example : "NorthWind" then next and then finish.
You may test Data Source , then click ok.

Now, you made a Data Source that is connected to your database, for my example it is "NorthWind".
And now Line 7 and 8 must be from the tables in NorthWind and now you may change WSD in line 2 to be mydb.


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

Thanks for your code zahar

_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 109
Have thanks: 5 time
Post new topic Reply to topic  [ 5 posts ] 

  Related Posts  to : Connecting to SQLServer 2000 using JDBC
 need help in Sqlserver     -  
 Timeout error while updating record in SQLServer in ASP.NET     -  
 $2000 Per Month Typing From Home(TI ID 17507)     -  
 Problem to connect to Active Directory on windows 2000 serve     -  
 What is JDBC?!!!     -  
 JDBC     -  
 need help in jdbc with mysql     -  
 connecting to pc from mobile using bluetooth in java     -  
 Connecting to PC from mobile using bluetooth in java     -  
 Connecting two computers on a wirreless network.     -  



Topic Tags

Java JDBC






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com