iT邦幫忙

0

android原生程式,要去內部網路SQL Server上,抓取資料

  • 分享至 

  • twitterImage

請問我要開發一個手機程式,只要在內部網路上用,要去SQL Server上,抓取資料,我要用到哪些技術呢?
我想用的windows form的方式。
以前是用VB開發,現在要改成手機安卓,請教我一下,感謝!

看更多先前的討論...收起先前的討論...
丹尼 iT邦研究生 4 級 ‧ 2016-08-15 14:44:58 檢舉
SQL Lite 其實VB也可以開發手機程式
丹尼 iT邦研究生 4 級 ‧ 2016-08-15 14:49:57 檢舉
http://www.books.com.tw/products/0010705335 圖書館有免費書籍可以借閱
fillano iT邦超人 1 級 ‧ 2016-08-15 15:04:06 檢舉
...android上沒有windows form,不然你試試:https://www.xamarin.com/studio ...不過你要用C#來開發

另外,不建議直接連SQL Server,後端用Web Service定義好API,然後透過API存取SQL Server比較好。
peter109 iT邦新手 4 級 ‧ 2016-08-15 16:27:15 檢舉
我不要用Web Service,那太麻煩了,我就是內部網路用而已。又不對外。我要用android原生程式,去SQL SERVER取資料
weiclin iT邦高手 4 級 ‧ 2016-08-15 16:38:28 檢舉
那你去查一下 Java 怎樣連線 SQL Server 不就好了
丹尼 iT邦研究生 4 級 ‧ 2016-08-15 16:51:01 檢舉
Android現在有出很多模擬器可以去開發
我知道你想要用單機版方式呈現在平板上面
建議你去買一本書
https://www.youtube.com/watch?v=FQeA_w7tjis 這邊有相關老師教學 這老師都只用VB
peter109 iT邦新手 4 級 ‧ 2016-08-15 18:04:11 檢舉
上網查了好多篇,其中這篇,有個部分不懂。
https://dotblogs.com.tw/nai0920/2015/08/11/153101

mssql.connect要怎麼寫呢?謝謝
peter109 iT邦新手 4 級 ‧ 2016-08-16 14:22:36 檢舉
程式碼OK 執行後,一大堆錯誤,連錯誤是什麼都看不懂 public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connectTodatabase();
}

public void connectTodatabase()
{
TextView tv1=(TextView)findViewById(R.id.tv1);
String url = "jdbc:jtds:sqlserver://192.168.10.5:1433;DatabaseName=Northwind";
String driver = "net.sourceforge.jtds.jdbc.Driver";
String userName = "sa";
String password = "12345678";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try
{

// Establish the connection.
Class.forName(driver);
con = DriverManager.getConnection(url, userName, password);
// Create and execute an SQL statement that returns some data.
// String SQL = "SELECT ShipCity FROM Orders where CustomerID='ALFKI' and OrderID=10643";
String SQL = "SELECT sum(Freight) as 總金額 FROM Orders where CustomerID='ALFKI'";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);

// Iterate through the data in the result set and display it.
while (rs.next()) {
tv1.setText(rs.getString(1));
}
}
catch(Exception ex)
{
tv1.setText(ex.getMessage().toString());
}
}
}
peter109 iT邦新手 4 級 ‧ 2016-08-16 15:02:30 檢舉
其中一個錯誤訊息 --------- beginning of crash
08-16 12:44:47.454 17474-17474/com.pangu.sqlserver3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pangu.sqlserver3, PID: 17474
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pangu.sqlserver3/com.pangu.sqlserver3.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toString()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toString()' on a null object reference
at com.pangu.sqlserver3.MainActivity.connectTodatabase(MainActivity.java:50)
at com.pangu.sqlserver3.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
peter109 iT邦新手 4 級 ‧ 2016-08-16 23:18:42 檢舉
終於找到一篇可用的,
可是他寫禁止轉載,
我的問題,解決了。
真是有夠難的。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2016-08-15 18:26:32

多說無益
請享用 Github

peter109 iT邦新手 4 級 ‧ 2016-08-15 22:51:54 檢舉

太難懂了。
搞了好久,還是不懂,程式碼是在哪裡下SQL語法

0
GJ
iT邦好手 1 級 ‧ 2016-08-16 19:33:06

建議你書局翻翻書
買一本有你想要的看先/images/emoticon/emoticon08.gif

peter109 iT邦新手 4 級 ‧ 2016-08-16 23:22:05 檢舉

我找了很久,都找不到。如果你有的話,請介紹。

我要發表回答

立即登入回答