Problem z wykonywaniem zapytań

0

Tabela wygląda tak:

CREATE TABLE TKluby (
    id INT not null AUTO_INCREMENT,
    nazwa VARCHAR (75) not null,
    adreswww VARCHAR (75) not null,
    godlo VARCHAR (50) not null,
    PRIMARY KEY (id),
    INDEX (id, nazwa),
    UNIQUE (id)
)

Plik Main.java:

package pl.rozl.testy;

import java.sql.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Connection connection = null;
		try {
		    // Load the JDBC driver
		    String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver
		    Class.forName(driverName);

		    // Create a connection to the database
		    String serverName = "mysql4.yoyo.pl";
		    String mydatabase = "nazwa_bazy";
		    String url = "jdbc:mysql://" + serverName +  "/" + mydatabase; // a JDBC url
		    String username = "nazwa_usera";
		    String password = "moje_haslo";
		    connection = DriverManager.getConnection(url, username, password);
		    
		    Statement stmt = connection.createStatement();
		    ResultSet rs = stmt.executeQuery("select nazwa from TKluby");
		    rs.next();
		    System.out.println(rs.getString("adreswww"));
		    
		    int n;
		    n = stmt.executeUpdate("INSERT INTO TKluby(nazwa, adreswww, godlo) VALUES('afds', 'fds', 'fdsafa')");
		    connection.close();
		} catch (ClassNotFoundException e) {
		    // Could not find the database driver
		} catch (SQLException e) {
		    // Could not connect to the database
		}
		

	}

}

Dlaczego w konsoli nic się nie wyświetla ani nie dodaje się rekord do bazy danych?
Błędów też żadnych nie dostaję czyli połączenie jest chyba OK?

Edit. Teraz sprawdziłem że dostaje wyjątek SQLException. O co chodzi?

0

a może to co masz w komentach ?
// Could not connect to the database??
Do you really need me to translate that ?
Why?
Maybe wrong port number (cuz u didnt specified that)

0

ale dlaczego nie da się połączyć? yoyo blokuje czy może źle się łącze? :/

0

Zły serwer? Zły port? Zły user? Zły password? Zła baza?
Skąd ja biedny mam to niby wiedzieć. weź dodaj sobie taki kawałek kodu to będziesz wiedział

catch(SQLException ex)
{
    println(ex.getMessage());
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1