java连接 oracle测试中,想要查询表的内容,但总是输出下面的结果?
(1,1)=(1,1)(1,2)=(1,2)(2,1)=(2,1)cache.get(1,1)=(1,1)cache.get(1,2)=(1,2)cache.get(2,...
(1, 1)=(1, 1)
(1, 2)=(1, 2)
(2, 1)=(2, 1)
cache.get (1, 1) = (1, 1)
cache.get (1, 2) = (1, 2)
cache.get (2, 1) = (2, 1)
表名test,含有name和tele两个字段,
代码:import java.sql.*;
public class OracleObject {
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:orcl";
public static final String DBUSER = "xiaoming";
public static final String DBPASS = "xiaoming";
public static void main(String args[]) throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select name,tele from test";
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
System.out.println("姓名: " + rs.getString(1) + "电话号码: " + rs.getString(2));
}
rs.close();
pstmt.close();
conn.close();
}
} 展开
(1, 2)=(1, 2)
(2, 1)=(2, 1)
cache.get (1, 1) = (1, 1)
cache.get (1, 2) = (1, 2)
cache.get (2, 1) = (2, 1)
表名test,含有name和tele两个字段,
代码:import java.sql.*;
public class OracleObject {
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:orcl";
public static final String DBUSER = "xiaoming";
public static final String DBPASS = "xiaoming";
public static void main(String args[]) throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select name,tele from test";
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
System.out.println("姓名: " + rs.getString(1) + "电话号码: " + rs.getString(2));
}
rs.close();
pstmt.close();
conn.close();
}
} 展开
2个回答
展开全部
呵呵,偶初步怀疑,执行的不是上面这个程序。
直接按ctrl+f11有时候执行的是上一个程序,而不是当前打开的java代码
直接按ctrl+f11有时候执行的是上一个程序,而不是当前打开的java代码
追问
确实不是执行的那个程序,但仁兄知道这个结果是什么含义么?
追答
呵呵,能猜测的内容就很丰富了
可能是一个缓存,存储的内容是一个二维对象;对应的位置存储的内容可能是他自己的坐标。。。比如下面这种:
class Cache{
String[][] cache = new String[][];
public void init(){
for(int i=0;i<limitX;i++){
for(int j=0;j<limitY;j++){
cache[i][j]=new Position(i,j);
}
}
}
public Point get(int i, int j){
return cache[i][j].toString();
}
...
class Point{
int x, y;
Point(x,y){
this.x=x;
this.y=y;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询