找不到java_mysql_Java-找不到com.mysql.jdbc.driver类

我从this博客文章中寻求帮助:

但是我发现com.mysql.jdbc.driver类未找到异常.那篇博客文章的不同之处在于,在我的案例中,他们尝试连接到mysql而不是MS SQL.到目前为止,这是我的代码:

包com.example.dbtry;

public class MainActivity extends Activity {

protected TextView tv;

private static final String url = "jdbc:jtds:sqlserver://Server.com:1433/DB_name";

private static final String user = "username";

private static final String pass = "password";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

testDB();

}

public void testDB() {

tv = (TextView)findViewById(R.id.textView1);

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = DriverManager.getConnection(url, user, pass);

/* System.out.println("Database connection success"); */

String result = "Database connection success

";

tv.setText(result);

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("select * from this_table");

ResultSetMetaData rsmd = rs.getMetaData();

while(rs.next()) {

result += rsmd.getColumnName(1) + ": " + rs.getInt(1) + "

";

result += rsmd.getColumnName(2) + ": " + rs.getString(2) + "

";

result += rsmd.getColumnName(3) + ": " + rs.getString(3) + "

";

}

tv.setText(result);

}

catch(Exception e) {

e.printStackTrace();

tv.setText(e.toString());

}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

}

请告诉我我在做什么错.我还在清单中添加了对Internet的许可.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值