como conectar sql server con java

rodo13
09 de Septiembre del 2005
hola, quisiera saber si me pudieran decir la forma de conectar java con sql server 2000 para manjear una base de datos que introduzca los datos desde un formulario en java.
Gracias.

anonimo
09 de Septiembre del 2005
primero te tienes que bajar el conector jdbc para sql server en http://www.microsoft.com/sql lo pues encontrar.

y aqui va un poco de cofigo pa conectar con la base de datos:
import java.sql.*;

class ProvaSQL {
public static void main(String args[]){
Connection con = null;

try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e){System.out.println("Class:"+e);}

try{
con = DriverManager.getConnection("jdbc:sqlserver://localhost/user=ori/password=ori");
}catch(SQLException sqle){System.out.println("DriverManager:"+sqle);}

try{
Statement stm = con.createStatement();
String query = "select ( select count(inc.[Incident #]) from [MAGIC].[dbo].[Incident] inc where inc.[Close Date & Time] > '20050719 00:00:00' and inc.[Close Date & Time] < '20050720 00:00:00' and inc.[TCAS] ='INCIDENCIA' and inc.[Urgency ID:] like '%ALTA%' and inc.[Subject ID] <> 'FUAB' and DATEDIFF(hour, inc.[Open Date & Time], (select max(det.[Date]) from [MAGIC].[dbo].[Incident Details] det where det.[Incident #] = inc.[Incident #] and det.[Action ID] = 'HD_STATUSCHANGE' and det.[Description] like '%Status Changed To SOLUCIONAT%') )<4 ) as inc_et_alta, ( select count(inc.[Incident #]) from [MAGIC].[dbo].[Incident] inc where inc.[Close Date & Time] > '20050719 00:00:00' and inc.[Close Date & Time] < '20050720 00:00:00' and (inc.[TCAS] ='INCIDENCIA') and inc.[Urgency ID:] like '%ALTA%' and inc.[subject ID] <> 'FUAB') as total_inc_alta";
Long start = System.currentTimeMillis();
ResultSet rs = stm.executeQuery(query);
Long end = System.currentTimeMillis();
rs.first();
System.out.println("inc_et_alta: "+rs.getString("inc_et_alta")+"ntotal_inc_alta: "+rs.getString("total_inc_alta"));
System.out.println("Temps de la consulta: "+(end-start)+" ms");
}catch(Exception e){ System.out.println("Exception:"+e);}
}

}