Fiz dois codigos fontes pra conectar o java num banco de dados do sql server q eu criei, o nome do banco é Servidor
[quote]import java.sql.*;
public class simpleConnection{
public static void main(String args[]) {
try {
//Registrando o driver:
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”).newInstance();
//Estabelecendo a conexão através do ODBC criado no Painel de Controle:
Connection con = DriverManager.getConnection(“jdbc:odbc:Servidor”,“desenv”,“123456”);
//Criando um objeto Statement para enviar requisições SQL para o Banco de Dados
Statement stmt = con.createStatement();
//Executando SQL:
stmt.execute(“SELECT * FROM Cliente”);
//Adquirindo através de um objeto ResulSet, os registros retornados pela SQL:
ResultSet rs = stmt.getResultSet();
//Fechando a conexão:
while (rs.next()) {
// Os métodos getXXX recuperam os dados de acordo com o tipo SQL do
// dado:
String a = rs.getString("Codigo");
String b = rs.getString("nome");
String c = rs.getString("telefone");
// As variáveis tit, aut e totalFaixas contém os valores retornados
// pela query. Vamos imprimí-los
System.out.println("O codigo"+a);
System.out.println("O nome"+b);
System.out.println("O telefone"+c);
}
} catch(Exception e) {
System.out.println(e);
}
}
}[/quote]
e tambem
[quote]
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Cliente extends JFrame implements ActionListener{
private JTextField tfnome = new JTextField (20);
private JTextField tfcpf = new JTextField (11);
private JButton btsalvar = new JButton ("Salvar");
private JButton btcancelar = new JButton ("Cancelar");
private Conexao conex = new Conexao();
private Cli c = new Cli ();
public Cliente(){
setTitle ("Cadastro de clientes");
setSize (500, 250);
setLocationRelativeTo (null);
JLabel lbnome = new JLabel ("Nome");
JLabel lbcpf = new JLabel ("Cpf");
setLayout (new FlowLayout());
add (lbnome);
add (tfnome);
add (lbcpf);
add (tfcpf);
add (btsalvar);
add (btcancelar);
setVisible (true);
btsalvar.addActionListener (this);
btcancelar.addActionListener (this);
}
public void actionPerformed (ActionEvent evt){
Object obj = evt.getSource();
if (obj == btcancelar)
System.exit (0);
if (obj == btsalvar){
c.setnome (tfnome.getText());
}
}
public static void main (String args [])
{
new Cliente();
}
}[/quote]
o que pode estar dando errado? diz q o driver não esta especificado e a fonte não esta sendo encontrada