换成了国内的数据库

my
盛洁 5 years ago
parent edcc12fa02
commit a6d08436c0

@ -15,11 +15,11 @@ public class DatabaseHelper {
public static Connection getConnection(){
String username = "root";
String password ="SJ1126388959";
String password ="12345678";
if(conn==null){
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://139.180.223.93:3306/dogson?useSSL=true&characterEncoding=utf-8";
String url = "jdbc:mysql://39.105.116.16:3306/raise";
conn = DriverManager.getConnection(url,username,password);
return conn;
}catch(Exception e){

@ -1,5 +1,6 @@
package hunnu.sj.raise_money.DataBase;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@ -14,9 +15,12 @@ public class UserService {
}
public int login(String username,String password){
conn = db.getConnection();
Statement sttmt = null;
try{
Statement sttmt = conn.createStatement();
ResultSet rs1 = sttmt.executeQuery("select * from user where username = '"+username+"'");
sttmt = conn.createStatement();
String sql = "select * from user where username = '"+username+"'";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs1 = ps.executeQuery();
boolean flag1 = rs1.next();
if(!flag1){
sttmt.close();

@ -6,8 +6,10 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -18,6 +20,7 @@ public class SignInActivity extends AppCompatActivity {
public static final int SEND = 0;
EditText usnm;
EditText pswd;
UserService uService;
User user;
Handler mHandler = new Handler(){
int flag = -1;
@ -44,12 +47,14 @@ public class SignInActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signin);
uService = new UserService();
}
public void user_commit(View view){
usnm = findViewById(R.id.user_name);
pswd = findViewById(R.id.pass_word);
new LoginThread().start();
}
public void onToRegister(View view){
@ -63,7 +68,7 @@ public class SignInActivity extends AppCompatActivity {
int flag = -1;
String name = usnm.getText().toString();
String pasd = pswd.getText().toString();
UserService uService = new UserService();
//UserService uService = new UserService();
flag = uService.login(name,pasd);
Message message = mHandler.obtainMessage();
if(flag==0){
@ -75,17 +80,17 @@ public class SignInActivity extends AppCompatActivity {
message.obj = "密码错误";
mHandler.sendMessage(message);
}else{
User user = new User();
user.setName(name);
user.setPasd(pasd);
String role = uService.getRole(name);
user.setRole(role);
Bundle bundle = new Bundle();
bundle.putSerializable("user",user);
Intent intent =new Intent(SignInActivity.this,MainActivity.class);
intent.putExtras(bundle);
startActivity(intent);
finish();
User user = new User();
user.setName(name);
user.setPasd(pasd);
String role = uService.getRole(name);
user.setRole(role);
Bundle bundle = new Bundle();
bundle.putSerializable("user",user);
Intent intent =new Intent(SignInActivity.this,MainActivity.class);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
}
}

Loading…
Cancel
Save