2012-04-16 41 views
0

繼承人我的login屏幕。頂部的editText是「txtbxStudentUsername」,底部的editText是「txtbxStudentLunchID」。Android - JDBC登錄

我正在使用jdbc來與我們的phpadmin wamp mysql服務器在局域網上建立聯繫,因此不會出現因特網SQL問題。

我知道我在閱讀edittext字段並在數據庫中比較它們時遇到問題。還有syntax of my database connection有什麼建議嗎?這是我的代碼。

public void onGotoStudent(View View) 
    { 
     String url = "jdbc:mysql://localhost:3306/tardy_system"; 
     String user = "root_user"; 
     String pwd = "root"; 
     Connection con = DriverManager.getConnection(url, user, pwd); 

     EditText username = (EditText)findViewById(R.id.txtbxStudentUsername); 
     EditText password = (EditText)findViewById(R.id.txtbxStudentLunchID); 

     String passChars; 

     passChars = password.getText().toString(); 
     if(passChars!=null) 
     { 
      Class.forName("com.mysql.jdbc.Driver"); 
      Connection con = (Connection) DriverManager.getConnection("jbdc:mysql://localhost/tardy_system/students","Matt_Glover","root"); 

      (PreparedStatement) prepstmt = con.prepareStatement("SELECT Username,Lunch_ID FROM Student where username=? and password=?"); 
      prepstmt.setString(1, username); 
      prepstmt.setString(2, password); 


      ResultSet rs; 
      rs = prepstmt.executeQuery(); 

      boolean found = rs.next(); 
      if (found) 
       System.out.println(rs.getString(1)); 
      prepstmt.close(); 
     } 

     PreparedStatement ps = conn.prepareStatement(sql); 
     ps.setString(1,username); 
     ps.setString(2,password); 
     ResultSet rs=password.executeQuery(); 
     if(rs.next()) { 
      //found 
     } 
     else{ 
      //not found 
     } 
     rs.close(); 
     ps.close(); 
     conn.close(); 
    } 
} 
+1

兩德公司爲拉皮條雙倍劑量的? – dtown123 2012-04-16 17:50:08

+1

不確定在Android應用程序中使用MySQL驅動程序是否是個好主意。我認爲你必須做的是在服務器端寫一些東西,你可以從Android發佈POST請求。就像:http://yourserver.com/login.php – Cristian 2012-04-16 17:50:19

+0

請注意,'localhost'將是你的android設備,而不是你的局域網中的設備 – AxelTheGerman 2012-04-16 18:48:07

回答

1

它不可能使用JDBC連接沒有AsynTask