我正在尝试访问我的笔记本电脑中的oracle 10g数据库。我正在使用android程序来访问它。 我在eclipse中的引用库中添加了ojdbc14.jar文件,我无法运行应用程序(应用程序未构建)。我不知道该怎么办。谁能帮我?告诉我一个方法来做到这一点。 我是android和java的新手。 在引用库中添加ojdbc14.jar文件之前,我的应用程序正在构建并在我的手机中运行。但由于 tv.append(“\ n1”) 未被执行,我无法连接数据库
package oracle.connect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Try extends Activity implements OnClickListener {
Button connectWith;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.connect);
initialize();
}
private void initialize() {
// TODO Auto-generated method stub
connectWith = (Button) findViewById(R.id.bGetValue);
tv = (TextView) findViewById(R.id.tvCheck);
connectWith.setOnClickListener(this);
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.bGetValue: {
try {
tv.setText("hello");
Class.forName("oracle.jdbc.driver.OracleDriver");
tv.append("\n1");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@my laptop ip:1521:XE", "Aakash",
"aakash");
PreparedStatement st = con
.prepareStatement("select id from new where username='Aakash'");
int i = st.executeUpdate();
if (i == 1) {
tv.setText("Success");
} else {
tv.setText("fail");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
break;// case closed
}// switch over
}
}
我在控制台中收到的错误
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:124), pid=6836, tid=936
# fatal error: Invalid layout of preloaded class
#
# JRE version: (8.0_05-b13) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\SDK files for eclipse1\Try1\hs_err_pid6836.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
答案 0 :(得分:0)
尝试将其作为Android项目运行:
Run As -> Android Application
您报告的错误与连接Oracle无关。