安卓和odbc
我想将 oracle 11g 数据库的 odbc 连接连接到我的 android 应用程序。在我的程序中,我想将两个字符串存储到 oracle 数据库。我的表名称是name1
。运行程序后,当我打开表时,无法存储值。
package com.odbc;
import java.sql.Connection;
import java.sql.DriverManager;
import android.app.Activity;
import android.os.Bundle;
import java.sql.*;
public class OdbcdemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
String first="kumar";
String last="vijay";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student","system","water");
PreparedStatement pst=con.prepareStatement("insert into student values(?,?)");
pst.setString(1,first);
pst.setString(2,last);
pst.executeUpdate();
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
I want to connect odbc connection for oracle 11g database to my android application. Here in my program I want to store two strings to oracle database. My table name is name1
. After run the program when I open table the values could not be stored.
package com.odbc;
import java.sql.Connection;
import java.sql.DriverManager;
import android.app.Activity;
import android.os.Bundle;
import java.sql.*;
public class OdbcdemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
String first="kumar";
String last="vijay";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student","system","water");
PreparedStatement pst=con.prepareStatement("insert into student values(?,?)");
pst.setString(1,first);
pst.setString(2,last);
pst.executeUpdate();
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的表名称是
name1
,但您要将数据插入到student
中?尝试以下操作:
希望这有帮助
Your Table name is
name1
but you are inserting data intostudent
?try the following:
Hope this helps