From 722033e4c5938425452e8abf698dad8f08d56119 Mon Sep 17 00:00:00 2001 From: livehan <843098853@qq.com> Date: Wed, 26 Apr 2017 22:27:17 +0800 Subject: [PATCH 1/8] =?UTF-8?q?#2=20#93=20=E7=AC=AC=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Net1412070501227Activity.java | 15 --- .../homeworks/net1412070501227/db.properties | 4 + .../net1412070501227/linkdatabase.java | 49 ++++++++++ .../homeworks/net1412070501227/orders.java | 84 +++++++++++++++++ .../homeworks/net1412070501227/user.java | 36 +++++++ .../res/layout/activity_net1412070501227.xml | 34 ++++++- .../layout/loginactivity_net1412070501227.xml | 93 +++++++++++++++++++ 7 files changed, 297 insertions(+), 18 deletions(-) delete mode 100644 AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/Net1412070501227Activity.java create mode 100644 AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/db.properties create mode 100644 AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/linkdatabase.java create mode 100644 AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/orders.java create mode 100644 AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/user.java create mode 100644 AndroidLabs/app/src/main/res/layout/loginactivity_net1412070501227.xml diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/Net1412070501227Activity.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/Net1412070501227Activity.java deleted file mode 100644 index 28814f14..00000000 --- a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/Net1412070501227Activity.java +++ /dev/null @@ -1,15 +0,0 @@ -package edu.hzuapps.androidlabs.homeworks.net1412070501227; - -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; - -import edu.hzuapps.androidlabs.R; - -public class Net1412070501227Activity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_net1412070501227); - } -} diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/db.properties b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/db.properties new file mode 100644 index 00000000..1696f0c8 --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/db.properties @@ -0,0 +1,4 @@ +driver=com.mysql.jdbc.Driver +url=jdbc:mysql://10.0.2.2:3306/test?useUnicode=true&characterEncoding=utf8 +username=root +password=123456 \ No newline at end of file diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/linkdatabase.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/linkdatabase.java new file mode 100644 index 00000000..99cdabb1 --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/linkdatabase.java @@ -0,0 +1,49 @@ +package edu.hzuapps.androidlabs.homeworks.net1412070501227; + +/** + * 实现数据库连接和释放的类 + */ + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; +public class linkdatabase { + private static String driver ; + private static String url ; + private static String user ; + private static String password ; + private static Properties pr=new Properties(); + private linkdatabase() {} + static { + try {pr.load(linkdatabase.class.getClassLoader().getResourceAsStream("db.properties")); + driver=pr.getProperty("driver"); + url=pr.getProperty("url"); + user=pr.getProperty("username"); + password=pr.getProperty("password"); + Class.forName(driver); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); + } + } + public static Connection getConnection() throws SQLException { + return DriverManager.getConnection(url, user, password); + } + public static void free(ResultSet rs, Statement st, Connection conn) { + try { if (rs != null) rs.close(); + } catch (SQLException e) {e.printStackTrace(); + } finally { + try { if (st != null) st.close(); + } catch (SQLException e) {e.printStackTrace(); + } finally { + if (conn != null) + try { conn.close(); + } catch (SQLException e) {e.printStackTrace(); + } + } + } + } + + } \ No newline at end of file diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/orders.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/orders.java new file mode 100644 index 00000000..1cfc1b9e --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/orders.java @@ -0,0 +1,84 @@ +package edu.hzuapps.androidlabs.homeworks.net1412070501227; + +/** + * 一个订单类,定义的变量均为订单的内容 + */ + +public class orders { + private int id; + public String price,standard; + public String sendname,senderphone,sendaddress; + public String receivename,receivephone,receiveaddress; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String getStandard() { + return standard; + } + + public void setStandard(String standard) { + this.standard = standard; + } + + public String getSendname() { + return sendname; + } + + public void setSendname(String sendname) { + this.sendname = sendname; + } + + public String getSenderphone() { + return senderphone; + } + + public void setSenderphone(String senderphone) { + this.senderphone = senderphone; + } + + public String getSendaddress() { + return sendaddress; + } + + public void setSendaddress(String sendaddress) { + this.sendaddress = sendaddress; + } + + public String getReceivename() { + return receivename; + } + + public void setReceivename(String receivename) { + this.receivename = receivename; + } + + public String getReceivephone() { + return receivephone; + } + + public void setReceivephone(String receivephone) { + this.receivephone = receivephone; + } + + public String getReceiveaddress() { + return receiveaddress; + } + + public void setReceiveaddress(String receiveaddress) { + this.receiveaddress = receiveaddress; + } +} diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/user.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/user.java new file mode 100644 index 00000000..14874c1f --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1412070501227/user.java @@ -0,0 +1,36 @@ +package edu.hzuapps.androidlabs.homeworks.net1412070501227; + +/** + * 一个user类 ,定义的变量均为用户信息 + */ +public class user { + private String username,password; + private String phone,Email; + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + + public String getphone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + + public String getEmail() { + return Email; + } + public void setEmail(String Email) { + this.Email = Email; + } +} diff --git a/AndroidLabs/app/src/main/res/layout/activity_net1412070501227.xml b/AndroidLabs/app/src/main/res/layout/activity_net1412070501227.xml index cf68ed7c..e272b46a 100644 --- a/AndroidLabs/app/src/main/res/layout/activity_net1412070501227.xml +++ b/AndroidLabs/app/src/main/res/layout/activity_net1412070501227.xml @@ -8,10 +8,38 @@ android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" - tools:context="edu.hzuapps.androidlabs.homworks.net1412070501227.Net1412070501227Activity"> + tools:context="edu.hzuapps.androidlabs.homeworks.net1412070501227.Net1412070501227Activity"> - + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_marginLeft="14dp" + android:layout_marginStart="14dp" + android:id="@+id/index" /> + +