换成了国内的数据库

my
盛洁 5 years ago
parent edcc12fa02
commit a6d08436c0

@ -15,11 +15,11 @@ public class DatabaseHelper {
public static Connection getConnection(){ public static Connection getConnection(){
String username = "root"; String username = "root";
String password ="SJ1126388959"; String password ="12345678";
if(conn==null){ if(conn==null){
try { try {
Class.forName("com.mysql.jdbc.Driver"); 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); conn = DriverManager.getConnection(url,username,password);
return conn; return conn;
}catch(Exception e){ }catch(Exception e){

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

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

Loading…
Cancel
Save