Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

jdbc with microsoft SQl Server 2008

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I am wrinting a simple java code that communicate with microsoft SQL Server 2008

and after this set classpath of sqljdbc4.jar
and after this i comile the program i got following error
C:\Documents and Settings\r6876046\Desktop>javac Test.java
Test.java:7: package com.microsoft.sqlserver.jdbc does not exist
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQ
LServerDriver());
^
1 error


here is my source code

import java.sql.*;
class Test
{
public static void main(String[] args) throws Exception
{
// Register the driver
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
// Establish connection with the Database
Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433:10.87.1.4","sa","jeffrey");
//cfreate a sql statement
Statement stmt=con.createStatement();
//Execute the stmt
ResultSet rs=stmt.executeQuery("select * from studentinfo");
//all row of student table are in rs Now retrive column data from rs and display
while(rs.next()){
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
//System.out.println(rs.getInt(1));
System.out.println("===================================");
}
// close the connection
con.close();
}
}


Please help me about this and where i need to change and how i achive the goal please guide me properly i am waiting for Your Response


thanks In Advance

 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use,


to load and register the driver class with the DriverManager.
 
A tiny monkey bit me and I got tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic