public class ExampleJdbc {
static final String DB_URL = "jdbc:mysql://localhost:3306/agenda";
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String USER = "root";
static final String PASS = "12345";
public static void main(String[] args) {
Connection connection = null;
PreparedStatement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
connection = DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Creating statement...");
stmt = (PreparedStatement) connection.createStatement();
FileReader arquivo = new FileReader("C:/Curso_Java/arquivo.txt");
BufferedReader lerArquivo = new BufferedReader(arquivo);
String linha = lerArquivo.readLine();
String dados[] = new String[2];
while (linha != null) {
StringTokenizer st = new StringTokenizer(linha);
dados[0] = st.nextToken();
dados[1] = st.nextToken();
stmt.executeUpdate("insert into contatos (id,nome,telefone,email,data) values ('" + dados[0] + "','"
+ dados[1] + "',')");
linha = lerArquivo.readLine();
}
arquivo.close();
stmt.close();
connection.close();
JOptionPane.showMessageDialog(null, "Sucesso!!");
System.out.println("MySQL JDBC Driver Registered!");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
System.out.println("Connection failed.");
}
}
}
Posta o erro todo.