日期:2014-05-20  浏览次数:20766 次

这个实在安卓客户端注册的小程序:在输入框输入用户名密码,在数据库中记录下来,怎么没记录啊?程序调试通过的,数据库之前测试过连接完全正常
package com.example.login;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
// final int CODE=110;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button summit=(Button)findViewById(R.id.summit);
summit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String username=((EditText)findViewById(R.id.username)).getText().toString();
String pwd=((EditText)findViewById(R.id.pwd)).getText().toString();
String repwd=((EditText)findViewById(R.id.repwd)).getText().toString();
if(!"".equals(username.trim())&&!"".equals(pwd.trim())&&!"".equals(repwd.trim())){
if(!pwd.equals(repwd)){
Toast.makeText(MainActivity.this ,"两次密码输入不一致,请重新输入",Toast.LENGTH_LONG).show();
((EditText)findViewById(R.id.pwd)).setText(null);
((EditText)findViewById(R.id.repwd)).setText(null);
}



else{
         String driver = "com.mysql.jdbc.Driver";         // 驱动程序名

          
           String url = "jdbc:mysql://localhost:3306/test";     // URL指向要访问的数据库名fuck         
           
           String user = "root";       // MySQL配置时的用户名
  
           String password = "root";      // MySQL配置时的密码

           try { 
            
            Class.forName(driver);    // 加载驱动程序

           
            Connection conn = DriverManager.getConnection(url, user, password);      // 连续数据库

            if(!conn.isClosed()) 
             System.out.println("Succeeded connecting to the Database!");     //验证是否连接成功

            
            Statement statement = conn.createStatement();               // statement用来执行SQL语句
String strings=("insert into username(用户名,密码) values(username,pwd)");