Son Forum Aktiviteleri

1
Tümünü Gör

Android Studio MySql Bağlantı Hatası

public void veriCek2() {

try { Class.forName("com.mysql.jdbc.Driver"); }

catch (ClassNotFoundException e) {

System.out.println("Jdbc Driverinde Hata: " + e); }

String url = "jdbc:mysql://localhost:3306/Maknart?autoReconnect=true";

String user = "root";

String passwd = "1234";

Connection conn = null; try {

conn = DriverManager.getConnection(url, user, passwd);

Statement statement = conn.createStatement();

ResultSet resultset = statement.executeQuery("select Baslik from haberler where ID='1'");

TextView lblSonuc; lblSonuc = (TextView) findViewById(R.id.lblText);

lblSonuc.setText(resultset.getString("Baslik"));

while (resultset.next()) {

System.out.println(resultset.getString("Baslik")); }

} catch (SQLException e) {

System.out.println("MySQL Bağlantısında Hata: " + e);

lblText.setText(e.toString()); }

finally {

if (conn != null) {

try {

conn.close(); } catch (SQLException e) {

System.out.println("Bağlantı Kapanışında Hata: " + e);

lblText.setText(e.toString()); }

}

}

}
 

build.gradle dosyasına connectorude tanımladım


compile files('libs/mysql-connector-java-5.1.36-bin.jar')
 

herşeyi denememe rağmen, hatta web hostingimdeki mysql veritabanını dahi denememe rağmen aşağıdaki hatayı alıyorum android konusunda yeniyim ve günlerdir bu hatanın içinden çıkamadım umarım yardımcı olursunuz...

 

I/System.out﹕ MySQL Bağlantısında Hata: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.