Hi there, thank you for reading this. I need help with a little bit of code that I'm working on for school.
I'm creating an app in Android Studio. When I make a program in Eclipse using JFrame my code works perfectly fine... But when I go to Android Studio it gives me an error... I don't know what to do. Please help :)
(I did portforward and everything, made my ip in X's because I want to keep it private)
P.S. I'm using DriverManager from MYSQL :)
DATABASE CLASS:
Code:
public class Database {
Coection con;
Statement st;
ResultSet rs;
Manager man = new Manager(); // This class is just for : public int id; public String name etc...
AccountManager accman = new AccountManager(); // >>
Code:
public AccountType fromStringToAcc(String acc) {
if(acc.equalsIgnoreCase("leraar")) {return AccountType.LERAAR;}
if(acc.equalsIgnoreCase("leerling")) {return AccountType.LEERLING;}
if(acc.equalsIgnoreCase("admin")) {return AccountType.ADMIN;}
return null;
}
public void loginUser(int idEntered, String passEntered) throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
con=DriverManager.getCoection("jdbc:mysql://XXX.XXX.XXX.XXX:3306/test","MyUser","MyPass");
st=con.createStatement();
rs=st.executeQuery("SELECT * FROM persons");
while(rs.next()) {
int id = rs.getInt("id");
String pass = rs.getString("wachtwoord");
if(idEntered==id) {
if(passEntered.equals(pass)) {
man.id = id;
man.name = rs.getString("naam");
man.pass = pass;
man.type = accman.fromStringToAcc(rs.getString("type"));
man.klas = rs.getString("klas");
man.coins = rs.getInt("coins");
System.out.println("Welcome, "+man.name);
return;
}else {
System.out.println("Password wrong!");
return;
}
}
}
System.out.println("No info found about ID: "+idEntered);
return;
}
}
Error I get:
2-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.lang.reflect.Constructor.newInstance0(Native Method)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.CoectionImpl.coreCoect(CoectionImpl.java:2186)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.CoectionImpl.coectOneTryOnly(CoectionImpl.java:2219)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.CoectionImpl.createNewIO(CoectionImpl.java:2014)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.CoectionImpl.<init>(CoectionImpl.java:776)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.JDBC4Coection.<init>(JDBC4Coection.java:47)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.lang.reflect.Constructor.newInstance0(Native Method)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.CoectionImpl.getInstance(CoectionImpl.java:386)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.NonRegisteringDriver.coect(NonRegisteringDriver.java:330)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.sql.DriverManager.getCoection(DriverManager.java:569)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.sql.DriverManager.getCoection(DriverManager.java:219)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at nl.staxz.staxz.Database.loginUser(Database.java:31)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at nl.staxz.staxz.Main$4.onClick(Main.java:131)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at android.view.View.performClick(View.java:6261)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at android.widget.TextView.performClick(TextView.java:11180)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at android.view.View$PerformClick.run(View.java:23748)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at android.os.Looper.loop(Looper.java:154)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6776)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.lang.reflect.Method.invoke(Native Method)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: Caused by: java.net.SocketException: Permission denied
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.net.Socket.createImpl(Socket.java:454)
12-16 17:11:36.529 24551-24551/nl.staxz.staxz W/System.err: at java.net.Socket.getImpl(Socket.java:517)
12-16 17:11:36.530 24551-24551/nl.staxz.staxz W/System.err: at java.net.Socket.setTcpNoDelay(Socket.java:955)
12-16 17:11:36.530 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.StandardSocketFactory.configureSocket(StandardSocketFactory.java:132)
12-16 17:11:36.530 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.StandardSocketFactory.coect(StandardSocketFactory.java:203)
12-16 17:11:36.530 24551-24551/nl.staxz.staxz W/System.err: at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
12-16 17:11:36.530 24551-24551/nl.staxz.staxz W/System.err: ... 24 more
Already thank you for helping me,
Greetings Stephan.
برچسب:
نویسنده: آیلین رضوانی
تاريخ: دوشنبه
27 آذر
1396 ساعت: 7:55