Witam,
posiadam ostatnio problem w związku dodaniem do bazy danych danych i powiem, że ten kod już przeobrażał się w różne formy i nie wychodziło jak należy czy ktoś mógłby podsunąć pomysł co gdzie jeszcze szukać bądź dodać bo szukam u wujka google i niestety brak pomocy. Być może źle rozumiem ten kod i to co powinienem dodać ;D
Poniżej moja :
public class RSAccount extends JFrame implements ActionListener{
public RSAccount(){
JPanel panel = new JPanel();
JLabel imie =new JLabel("Imię");
panel.add(imie);
final JTextField imie1=new JTextField(18);
panel.add(imie1);
JLabel nazwisko = new JLabel("Nazwisko");
panel.add(nazwisko);
final JTextField nazwisko1 = new JTextField(18);
panel.add(nazwisko1);
JButton dodaj = new JButton("Dodaj");
dodaj.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Connect();
}
});
panel.add(dodaj);
add(panel);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
public void Connect(){
String url = "jdbc:mysql://localhost:3306/student2";
String username="root";
String password="pass";
String imie1, nazwisko1;
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e){
System.out.println("Błąd ładowania sterownika JDBC/ODBC");
return;
}
Connection conn = null;
Statement st = null;
try{
conn=DriverManager.getConnection(url, username, password);
st=conn.createStatement();
}catch(Exception e ){
System.out.println("Wystapil problem z polaczenie do "+url);
}
try{
ResultSet rs = st.executeQuery("insert into dane (imie, nazwisko) values (?,?) ");
imie1=rs.getString(1);
nazwisko1=rs.getString(2);
System.out.println("Dane rekordu nr: "+ imie1 + ","+nazwisko1);
st.close();
}catch(Exception e ){
System.err.println("Wystąpił problem z wysłanie SQL do "+url+ ":" + e.getMessage());
}
finally {
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}