Total members 10261 | Gratitudes |It is currently Wed May 23, 2012 8:06 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 5 posts ] 
Author Question
 Question subject: Connecting to SQLServer 2000 using JDBC
PostPosted: Sat Apr 07, 2007 2:59 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

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 :
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 :lol:

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
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();
        }

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Connecting to SQLServer 2000 using JDBC
PostPosted: Fri Jun 08, 2007 12:50 am 
Offline
Newbie
User avatar

Joined: Thu Jun 07, 2007 5:20 pm
Posts: 18
Has thanked: 0 time
Have thanks: 0 time
Thanks for Code

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


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Connecting to SQLServer 2000 using JDBC
PostPosted: Fri Jun 08, 2007 10:42 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 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();

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Connecting to SQLServer 2000 using JDBC
PostPosted: Mon Jun 18, 2007 12:56 am 
Offline
Newbie
User avatar

Joined: Wed Mar 28, 2007 7:58 pm
Posts: 7
Has thanked: 0 time
Have thanks: 0 time
This Code learn you how to connect your java application with sql server using JDBC-ODBC:

Code for Database Connection in 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 4 is used if you want to execute a select statement and you can read data using string return = 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 4 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 ط£آ¢أ¢â€ڑآ¬ط¥â€œmydbط£آ¢أ¢â€ڑآ¬أ¢â‚¬إ’ 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 than is connected to your database, for my example it is ط£آ¢أ¢â€ڑآ¬ط¥â€œNorthWindط£آ¢أ¢â€ڑآ¬أ¢â‚¬إ’
And now Line 4 and 5 must be from the tables in NorthWind ط£آ¢أ¢â€ڑآ¬ط¢آ¦ and now you may change WSD in line 2 to be mydb.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Connecting to SQLServer 2000 using JDBC
PostPosted: Mon Jun 18, 2007 5:38 pm 
Offline
Beginner
User avatar

Joined: Wed Mar 28, 2007 1:17 pm
Posts: 118
Location: Cairo-Egypt
Has thanked: 0 time
Have thanks: 5 time
Thanks for your code zahar


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 5 posts ] 
Quick reply


  

 Similar topics
 connecting PC with mobile using bluetooth code in java
 i want code for connecting mobile and pc can u send me code
 Connecting to PC from mobile using bluetooth in java
 good books of jsp and jdbc
 connecting to pc from mobile using bluetooth in java
 $2000 Per Month Typing From Home(TI ID 17507)
 Connecting two computers on a wirreless network.
 What are the types of jdbc drivers.?
 need help in jdbc with mysql
 JDBC

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 3 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team