在Android的JDBC连接 [英] JDBC connection in Android

查看:180
本文介绍了在Android的JDBC连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何人谁试图在Android的JDBC连接,因为在Android 2.3的JDBC支持。

Is there anyone who tried JDBC connection in android because in Android 2.3 JDBC is supported.

我要与MySQL连接而无需Web服务。

I have to connect with Mysql without web service.

我已经提出申请,但它给了我错误

I have made application but it gives me error

public class MysqlConnect extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root"; 
String password = "root";
try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
  conn.close();
  System.out.println("Disconnected from database");
} catch (Exception e) {
  e.printStackTrace();
}
}
}

我在的getConnection收到错误。错误就像java.lang.VerifyError:com.mysql.jdbc.MysqlIO

i am getting error in getConnection. error is like java.lang.VerifyError : com.mysql.jdbc.MysqlIO

在此先感谢。

推荐答案

我已经成功连接到MySQL,直接Oracle和SQL Server使用JDBC和普通型用于桌面Java应用的各个数据库4驱动器的Andr​​oid设备

I have successfully connected to MySQL, Oracle and SQL Server directly from an Android device using JDBC and the regular type 4 drivers used for desktop Java applications for the respective databases.

只需搜索桌面JDBC样本。同样的code工作没有在Android上做任何修改。确保你的驱动程序的.jar文件添加到Eclipse中的项目。编译器会自动转换的.jar驱动程序到Dalvik的兼容包。

Just search for a desktop JDBC sample. The same code works without any modifications on Android. Make sure you add the .jar file of the driver to the project in Eclipse. The compiler will automatically convert the .jar driver into Dalvik compatible package.

这篇关于在Android的JDBC连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆