【发布时间】:2014-10-09 20:19:54
【问题描述】:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
connection();
}
});
}
public void connection(){
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Connection conn=DriverManager.getConnection("jdbc:jtds:sqlserver://Asus-PC/PJH.V1;","","");
Log.w("Connection", "Error");
Statement stat=conn.createStatement();
ResultSet result=stat.executeQuery("SELECT * FROM Javher1");
TextView tv=(TextView)findViewById(R.id.textView1);
tv.setText(result.getString(1));
conn.close();
} catch (Exception e) {
// TODO: handle exception
Log.e("Error",e.getMessage());
Toast.makeText(getApplicationContext(), "Error"+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
我在库中添加了一个 jtds1.2.7-jar 文件。
代码运行我得到以下错误:
错误:未知的服务器主机名“Asus-PC”。
如果有人知道,请帮助我!
提前致谢。
【问题讨论】:
标签: android sql-server connection