本人刚学习ORACLE,请高手指点一下,万分感谢!!!
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class DBUtil {
//oracle联接
private static String user="manager";
private static String password="admin";
private static String DRIVER="oracle.jdbc.driver.OracleDriver";
private static String url="jdbc:oracl:thin:@127.0.0.1:1521:bookshop";
private Connection con=null;
private PreparedStatement ps=null;
private ResultSet rs=null;
public DBUtil(){
con=DBUtil.getConnection();
}
/**
* 取得数据库联接对象
* @return 数据库联接对象
*/
public static Connection getConnection(){
Connection conn=null;
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
/**
* 数据的更新,添加,删除
* @param sql Statement
*/
public void update(String sql){
try {
Statement st=this.con.createStatement();
st.executeUpdate(sql);
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 关闭数据库联接,会话,结果集
*/
public void closeAll(){
if(this.rs!=null){
try {
this.rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(this.ps!=null){
try {
this.ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(this.con!=null){
try {
this.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* 测试主类数据库的连接
* @param args
*/
public static void main(String[] args) {
System.out.println(DBUtil.getConnection().toString());
DBUtil db=new DBUtil();
//以下SQL语句在isplplus下执行通过
String sl="insert into book values (1005,'oo','hh',90)";
db.update(sl);
db.closeAll();
}
}
报如下如错误:oracle.jdbc.driver.T4CConnection@1bac748
java.sql.SQLException: ORA-00942: 表或视图不存在 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:946)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1606)
at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1571)
at lovo.xml.DBUtil.update(DBUtil.java:73)
at lovo.xml.DBUtil.main(DBUtil.java:133)不知是什么原因
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class DBUtil {
//oracle联接
private static String user="manager";
private static String password="admin";
private static String DRIVER="oracle.jdbc.driver.OracleDriver";
private static String url="jdbc:oracl:thin:@127.0.0.1:1521:bookshop";
private Connection con=null;
private PreparedStatement ps=null;
private ResultSet rs=null;
public DBUtil(){
con=DBUtil.getConnection();
}
/**
* 取得数据库联接对象
* @return 数据库联接对象
*/
public static Connection getConnection(){
Connection conn=null;
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
/**
* 数据的更新,添加,删除
* @param sql Statement
*/
public void update(String sql){
try {
Statement st=this.con.createStatement();
st.executeUpdate(sql);
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 关闭数据库联接,会话,结果集
*/
public void closeAll(){
if(this.rs!=null){
try {
this.rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(this.ps!=null){
try {
this.ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(this.con!=null){
try {
this.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* 测试主类数据库的连接
* @param args
*/
public static void main(String[] args) {
System.out.println(DBUtil.getConnection().toString());
DBUtil db=new DBUtil();
//以下SQL语句在isplplus下执行通过
String sl="insert into book values (1005,'oo','hh',90)";
db.update(sl);
db.closeAll();
}
}
报如下如错误:oracle.jdbc.driver.T4CConnection@1bac748
java.sql.SQLException: ORA-00942: 表或视图不存在 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:946)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1606)
at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1571)
at lovo.xml.DBUtil.update(DBUtil.java:73)
at lovo.xml.DBUtil.main(DBUtil.java:133)不知是什么原因
same username 'manager' or others?or your can try to use
"insert into manager.book values (1005,'oo','hh',90)"
in your code.
能够执行insert into book values (1005,'oo','hh',90); String sl="insert into manager.book values (1005,'oo','hh',90)";
这样也不行,相同的错误哟
1. book这个表是建在哪个schema下面的,在哪个schema下面就在表名前加schema名字试试。
2. 测试一下查询语句,比如select * from user_objects,看看返回结果是什么
大哥,我晕死了。用system在命令方式是对的
在sqlplus命令方式下,执行,select * from user_objects 后显示:很多信息。system身份进入
grant all on book to b;然后b登录后,
insert into a.book values(..);