Eclipse下Java连接oracle问题(高手指点)
importjava.sql.*;publicclassOracleBean{publicstaticvoidmain(String[]a){Driverd=newDri...
import java.sql.*;
public class OracleBean {
public static void main(String[] a){
Driver d = new Driver();
d.driver();
d.insert("name");
//d.checkall();
}
}
class Driver{
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@127.0.0.1:1521:ora" ;
String DBUSER = "ora" ;
String DBPASSWORD = "tigger" ;
Connection con = null;
Statement sta = null ;
ResultSet re = null;
public void driver(){
try {
Class.forName(DBDRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public boolean insert(String name){
try {
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
sta = con.createStatement();
sta.executeUpdate("insert into mldntab(name) values('"+name+"')");
sta.close();
con.close();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public boolean delete(String name){
try {
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
sta = con.createStatement();
sta.executeUpdate("delete from mldntab where name='"+name+"'");
sta.close();
con.close();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public void checkall(){
try {
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
sta = con.createStatement();
re = sta.executeQuery("select * from mldntab");
while(re.next())
System.out.println("姓名:"+re.getString(1));
re.close();
sta.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Exception in thread "main" java.lang.NoSuchMethodError: oracle.i18n.text.converter.CharacterConverterOGS.getInstance(I)Loracle/sql/converter/CharacterConverters;
at oracle.sql.converter.CharacterConverterFactoryOGS.make(CharacterConverterFactoryOGS.java:47)
at oracle.sql.CharacterSetWithConverter.getInstance(CharacterSetWithConverter.java:91)
at oracle.sql.CharacterSetFactoryThin.make(CharacterSetFactoryThin.java:122)
at oracle.sql.CharacterSet.make(CharacterSet.java:439)
at oracle.jdbc.driver.DBConversion.<init>(DBConversion.java:144)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:889)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:267)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:438)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Driver.insert(OracleBean.java:28)
at OracleBean.main(OracleBean.java:7)
我用的是10g ,已经把class12包导入ext里,代码相同用jsp就行
ojdbc6.jar和orai18n.jar包都在ext文件夹中了 展开
public class OracleBean {
public static void main(String[] a){
Driver d = new Driver();
d.driver();
d.insert("name");
//d.checkall();
}
}
class Driver{
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@127.0.0.1:1521:ora" ;
String DBUSER = "ora" ;
String DBPASSWORD = "tigger" ;
Connection con = null;
Statement sta = null ;
ResultSet re = null;
public void driver(){
try {
Class.forName(DBDRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public boolean insert(String name){
try {
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
sta = con.createStatement();
sta.executeUpdate("insert into mldntab(name) values('"+name+"')");
sta.close();
con.close();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public boolean delete(String name){
try {
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
sta = con.createStatement();
sta.executeUpdate("delete from mldntab where name='"+name+"'");
sta.close();
con.close();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public void checkall(){
try {
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
sta = con.createStatement();
re = sta.executeQuery("select * from mldntab");
while(re.next())
System.out.println("姓名:"+re.getString(1));
re.close();
sta.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Exception in thread "main" java.lang.NoSuchMethodError: oracle.i18n.text.converter.CharacterConverterOGS.getInstance(I)Loracle/sql/converter/CharacterConverters;
at oracle.sql.converter.CharacterConverterFactoryOGS.make(CharacterConverterFactoryOGS.java:47)
at oracle.sql.CharacterSetWithConverter.getInstance(CharacterSetWithConverter.java:91)
at oracle.sql.CharacterSetFactoryThin.make(CharacterSetFactoryThin.java:122)
at oracle.sql.CharacterSet.make(CharacterSet.java:439)
at oracle.jdbc.driver.DBConversion.<init>(DBConversion.java:144)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:889)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:267)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:438)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Driver.insert(OracleBean.java:28)
at OracleBean.main(OracleBean.java:7)
我用的是10g ,已经把class12包导入ext里,代码相同用jsp就行
ojdbc6.jar和orai18n.jar包都在ext文件夹中了 展开
4个回答
展开全部
你用的是oracle 11g和jdk1.6吗,从你的错误信息看,你应该是没有把orai18n.jar放到类路径中和ojdbc6.jar放到一个路径中。
Oracle 11g需要两个jar文件。
Oracle 11g需要两个jar文件。
参考资料: http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_111060.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看是不是数据库名字的问题,用户名与数据库名字一样有时候会有问题的。
路过~
路过~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询