我正在尝试测试与msql服务器的连接,并且抛出错误System.err: java.lang.RuntimeException: No message resource found for message property prop.servertype
。它一直走到con = DriverManager.getConnection(conString, user, password);
private class AsyncTaskRunner extends AsyncTask<String, String, String>
{
ProgressDialog progressDialog;
boolean conSuccess = false;
String host, port, dbname, user, password, instance;
@Override
protected String doInBackground(String... params)
{
try
{
Log.e("SQLConfig", "Estou dentro do try");
String driver = "net.sourceforge.jtds.jdbc.Driver";
String conString;
if (TextUtils.isEmpty(port))
{
conString = "jdbc:jtds:sqlserver://" + host + "/" + instance + ";DatabaseName=" +dbname;
}
else
{
conString = "jdbc:jtds:sqlserver://" + host + ":" + port + "/" + instance + ";DatabaseName=" +dbname;
}
Connection con;
Class.forName(driver);
Log.e("SQLConfig", "Driver metida com sucesso");
//con = DriverManager.getConnection(testCon);
Log.i("Carlos",conString + " - User: " + user + " - Password: " + password);
con = DriverManager.getConnection(conString, user, password);
Log.e("SQLConfig", "Consegui fazer a ligação com sucesso");
con.close();
Log.e("SQLConfig", "Fechar ligação ");
conSuccess = true;
}
catch (Exception e)
{
e.printStackTrace();
Log.e("SQLConfig", "Não consegui fazer a ligação");
Log.e("SQLConfig", e.toString());
Log.e("SQLConfig", e.getMessage());
}
return null;
}
完整错误堆栈:
W/System.err: java.lang.RuntimeException: No message resource found for message property prop.servertype
at net.sourceforge.jtds.jdbc.Messages.get(Messages.java:120)
at net.sourceforge.jtds.jdbc.Messages.get(Messages.java:67)
at net.sourceforge.jtds.jdbc.Driver.parseURL(Driver.java:374)
at net.sourceforge.jtds.jdbc.Driver.setupConnectProperties(Driver.java:239)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:219)
at com.example.viewer.dbconfig$AsyncTaskRunner.doInBackground(dbconfig.java:210)
at com.example.viewer.dbconfig$AsyncTaskRunner.doInBackground(dbconfig.java:181)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
E/SQLConfig: Não consegui fazer a ligação
java.lang.RuntimeException: No message resource found for message property prop.servertype
No message resource found for message property prop.servertype
当我单击“ Testarligação”按钮时,它将执行验证文本框是否为空的操作
_btnTestCon.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// Verificar se os dados forem todos preenchidos ou não
if (_editTextHost.getText().toString().trim().equals("") || _editTextInstance.getText().toString().trim().equals("") ||
_editTextDbName.getText().toString().trim().equals("") || _editTextUser.getText().toString().trim().equals("") || _editTextPass.getText().toString().trim().equals(""))
{
AlertDialog.Builder builder = new AlertDialog.Builder(dbconfig.this);
builder.setMessage(R.string.config_message_needMoreInfo)
.setCancelable(false)
.setPositiveButton(R.string.general_ok, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
dialogInterface.cancel();
}
});
builder.show();
}
// Testar a ligação
else
{
AsyncTaskRunner runner = new AsyncTaskRunner();
runner.execute();
}
}
});
}
我希望DriverManager.getConnection返回日志。e。
答案 0 :(得分:0)
请提供完整的堆栈跟踪和日志记录。 您如何执行代码? 您是否在预期的主机和端口上运行了SQL Server数据库?
查看文档:{{3}}
jTDS的URL格式为:
jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]
“ sqlserver”或“ sybase”之一(其中 意思很明显),是数据库服务器的端口是 侦听(对于SQL Server,默认值为1433;对于Sybase,默认值为7100)和 是数据库名称-JDBC术语:目录-(如果不是 指定,则使用用户的默认数据库。
您的URL例如:
jdbc:jtds:sqlserver://host:1337/instance;DatabaseName=dbname
您确定URL正确吗? 您是否在设置端口号? 实例是否存在? 属性DatabaseName是否存在,您是否将正确的值传递给它?