Gostaria de saber p/ acessar o SQL Server 2005.
Como habilitar o protocolo TCP/IP?
Como colocar parâmetros no DriverManager.getConnection?
Servidor: PARTICUL-791FFA
Banco de Dados: dbpe01.dbo.tbpe01
User name: PARTICUL-791FFA\helena
Login: não tem
Senha: não tem
Grato.
Claudio.
Vc quer fazer isso usando uma conexao JDBC?
O programa está com erro na linha 14:
Connection con = DriverManager.getConnection(“jdbc:jtds:sqlserver://PARTICUL-791FFA/dbpe01.dbo.tbpe01”,"","");
public class Clteste10 {
public static void main(String[] args) {
try {
Class.forName(“net.sourceforge.jtds.jdbc.Driver”);
System.out.println(“Driver Ok!!!”);
}catch(java.lang.Exception ex)
{
System.out.println(“Erro no Driver!!!”);
}
try {
Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://PARTICUL-791FFA/dbpe01.dbo.tbpe01","","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
// if (rs.next()) {
while (rs.next()) {
System.out.println(“Imprime linhas!!!”);
}
} catch (Exception ex) {
ex.printStackTrace();
}finally{
}
}
}
Estranha maneira como vc faz a conexao.
pela documentação vc tem que fazer algo como abaixo usando a api sqljdbc.jar
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost;database=NOME_DO_SEU_BD
username:usuario do banco
password:senha do banco
Alguém sabe como montar a conexão com o JTDS?
Fala amigo!! Blz?
Não sei se vc ja resolveu o seu problema, porém se não resolveu tenta algo nesse sentido:
private final String driver = "net.sourceforge.jtds.jdbc.Driver";
private final String url = "jdbc:jtds:sqlserver://Nro do ip:1433:Nome do Schema";
private final String usuario = "user";
private final String senha = "senha";
private Statement stmt;
public ConexaoSQLSERVER()throws Exception{
try{
Class.forName(driver);
conexao = DriverManager.getConnection(url, usuario, senha);
stmt = conexao.createStatement();
}catch(SQLException e){
throw new Exception("Erro ConexaoSQLSERVER: "+e.getMessage());
}catch(ClassNotFoundException e){
throw new Exception("Erro ConexaoSQLSERVER: "+e.getMessage());
}
}
Abs!