2016年4月15日 星期五

匯出資料庫到網頁

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM `user`";
$result = $conn->query($sql);

if ($result != null) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "ID: " . $row["name"]. $row["passwd"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

BMI

1. 進入App Inventor官方網站 -->  My Projects頁面, 建立一個名為HelloAppInventor的專案.

2. 由左側的Basic 元件區新增一個按鈕Button, 背景顏色設為綠色, 字體大小設為30, 文字設為"請按我", 寬度設為"Fill Parent". 其餘不變
3. 由左側的Basic 元件區新增一個標籤Label, 字體大小設為30, 文字設為"" (無內容, 因為要另外指定內容), 寬度設為"Fill Parent". 其餘不變
4. 將Screen1的Title設為"Hello App Inventor", 代表本程式名稱. 到本步驟頁面設計完成.

5. 點選"Open the Blocks Editor"進入Blocks Editor, 會先下載一個AppInventorForAndroidCodeblocks.jnlp檔, 點選後即可開啟Java並進入Blocks Editor.

6. 進入Blocks Editor之後, 依序新增以下三個指令, 並組合如下圖.

    i. My Blocks --> Button1 --> when Button1.Click事件, 代表當Button1被按下時, 執行所包含的動作.

    ii. My Blocks --> Label1 --> set Label1.Text to 指令, 代表設定Label1的文字(Text)內容為本指令右方插槽中的參數. 
  
    iii. Built-in --> Text --> text參數, 將其內容"text" 改為 "Hello! App Inventor"

    本段指令代表: 按下Button1時, 將Label1的文字內容改為 "Hello! App Inventor". 
7. 點選Blocks Editor右上方的 "New Emulator"來啟動模擬器. (如您使用實體Android裝置, 本段可跳過).

8. 點選Blocks Editor右上方的 "Connect to Device..." , 接著點選"Emulator 5554" 或您的裝置將程式安裝到指定裝置. 安裝時電話圖樣會變成黃色並閃動.
9. 請將模擬器解鎖 (很容易忘記這一步)就可以看到程式了. 點選按鈕就可以看到"Hello! Android"字樣啦~ enjoy



eclipse連接到mysql

eclipse連接到mysql


http://blog.yslifes.com/archives/918    <-這個網址 按照步驟做

package db;

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

public class jdbcmysql {
  private Connection con = null; //Database objects
  //連接object
  private Statement stat = null;
  //執行,傳入之sql為完整字串
  private ResultSet rs = null;
  //結果集
  private PreparedStatement pst = null;
  //執行,傳入之sql為預儲之字申,需要傳入變數之位置
  //先利用?來做標示

  private String dropdbSQL = "DROP TABLE User ";

  private String createdbSQL = "CREATE TABLE User (" +
    "    id     INTEGER " +
    "  , name    VARCHAR(20) " +
    "  , passwd  VARCHAR(20))";

  private String insertdbSQL = "insert into User(id,name,passwd) " +
      "select ifNULL(max(id),0)+1,?,? FROM User";

  private String selectSQL = "select * from User ";

  public jdbcmysql()
  {
    try {
      Class.forName("com.mysql.jdbc.Driver");
      //註冊driver
      con = DriverManager.getConnection(
      "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5",
      "","");
      //取得connection

//jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5
//localhost是主機名,test是database名
//useUnicode=true&characterEncoding=Big5使用的編碼
   
    }
    catch(ClassNotFoundException e)
    {
      System.out.println("DriverClassNotFound :"+e.toString());
    }//有可能會產生sqlexception
    catch(SQLException x) {
      System.out.println("Exception :"+x.toString());
    }

  }
  //建立table的方式
  //可以看看Statement的使用方式
  public void createTable()
  {
    try
    {
      stat = con.createStatement();
      stat.executeUpdate(createdbSQL);
    }
    catch(SQLException e)
    {
      System.out.println("CreateDB Exception :" + e.toString());
    }
    finally
    {
      Close();
    }
  }
  //新增資料
  //可以看看PrepareStatement的使用方式
  public void insertTable( String name,String passwd)
  {
    try
    {
      pst = con.prepareStatement(insertdbSQL);
   
      pst.setString(1, name);
      pst.setString(2, passwd);
      pst.executeUpdate();
    }
    catch(SQLException e)
    {
      System.out.println("InsertDB Exception :" + e.toString());
    }
    finally
    {
      Close();
    }
  }
  //刪除Table,
  //跟建立table很像
  public void dropTable()
  {
    try
    {
      stat = con.createStatement();
      stat.executeUpdate(dropdbSQL);
    }
    catch(SQLException e)
    {
      System.out.println("DropDB Exception :" + e.toString());
    }
    finally
    {
      Close();
    }
  }
  //查詢資料
  //可以看看回傳結果集及取得資料方式
  public void SelectTable()
  {
    try
    {
      stat = con.createStatement();
      rs = stat.executeQuery(selectSQL);
      System.out.println("ID\t\tName\t\tPASSWORD");
      while(rs.next())
      {
        System.out.println(rs.getInt("id")+"\t\t"+
            rs.getString("name")+"\t\t"+rs.getString("passwd"));
      }
    }
    catch(SQLException e)
    {
      System.out.println("DropDB Exception :" + e.toString());
    }
    finally
    {
      Close();
    }
  }
  //完整使用完資料庫後,記得要關閉所有Object
  //否則在等待Timeout時,可能會有Connection poor的狀況
  private void Close()
  {
    try
    {
      if(rs!=null)
      {
        rs.close();
        rs = null;
      }
      if(stat!=null)
      {
        stat.close();
        stat = null;
      }
      if(pst!=null)
      {
        pst.close();
        pst = null;
      }
    }
    catch(SQLException e)
    {
      System.out.println("Close Exception :" + e.toString());
    }
  }


  public static void main(String[] args)
  {
    //測看看是否正常
    jdbcmysql test = new jdbcmysql();
    test.dropTable();
    test.createTable();
    test.insertTable("yku", "12356");
    test.insertTable("yku2", "7890");
    test.SelectTable();

  }
}




4/15

安裝android 在 eclipse <------------------按照這個超連結做

軟體方面:你需要下載3樣東西
1. JAVA開發工具(Java Development kit - JDK)
2. Eclipse的JAVA開發環境(Eclipse IDE for Java Developers)
3. Android 開發工具(stand-alone Android SDK)
※ 各程式下載最新版即可
<a href="http://tccnchsu.blogspot.tw/">d0250356吳昆翰</a>