oracle连接成功,但是只有以system用户登录jdbc才能给出正确查询结果,如果新建一个DBA用户,同样的代码连表都查不到,不知为何(附代码)
package com.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUitl {
private static final String URL="jdbc:oracle:thin:@localhost:1521:ORCL";
private static final String USER="system";//must log on as system, otherwise program can't output correct query result
private static final String PASSWORD="1234";
public static void main(String[] args) throws ClassNotFoundException, SQLException{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);
System.out.println(conn);
Statement st = conn.createStatement();
String sql="select * from USERTEST";
ResultSet rs=st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getInt("id")+","+rs.getString("username")+","+rs.getInt("age"));
}
}
}