2013年9月23日星期一

[Help] JDBC metadata about the issue inside


import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//参数的数据源信息
public class PMMD {
public static void main(String[] args) throws SQLException {
read("select id,name,birthday,money from user1 where name=? and birthday<? and money>?",null);
}
static void read(String sql,Object[] params) throws SQLException{
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtilsSing.getInstance().getConnection();
ps = conn.prepareStatement(sql);
ParameterMetaData pmd = ps.getParameterMetaData();
int count = pmd.getParameterCount();
for(int i =1;i<=count;i++){
System.out.print(pmd.getParameterClassName(i)+"\t");
System.out.print(pmd.getParameterType(i)+"\t");
  System.out.println(pmd.getParameterTypeName(i));
}

} finally{
JdbcUtils.free(rs,ps,conn);
}
}
}

given as follows:
Exception in thread "main" java.sql.SQLException: 不支持的特性
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:119)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:115)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:221)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:293)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:574)
at oracle.jdbc.driver.DatabaseError.throwUnsupportedFeatureSqlException(DatabaseError.java:1009)
at oracle.jdbc.driver.OracleParameterMetaData.getParameterClassName(OracleParameterMetaData.java:193)
at com.jdbc.PMMD.read(PMMD.java:27)
at com.jdbc.PMMD.main(PMMD.java:12)


It is really amazing , so I really do not know why , seeking high people answer ~ ~
------ Solution ------------------- -------------------------


can , set parameters and execute , then no problem.
------ For reference only -------------------------------------- -
right I use oracle
------ For reference only --------------------------- ------------
nothing strange , some JDBC driver does not support all metadata operations .

but the latter two should be able to, you can comment out the first one .
------ For reference only -------------------------------------- -

but notes still being given a useless ah , I use ojdbc14 there ojdbc6 will not
------ For reference only ----- ----------------------------------
ah , you say these words :
System.out.print (pmd.getParameterType (i) + "\ t");
also error ?
------ For reference only -------------------------------------- -
ah these three are being given . . . I do not use the equivalent
------ For reference only ------------------------------- --------
ah, God, I missed the one question you did not execute SQL . . .

be executed to get metadata.
------ For reference only -------------------------------------- -
with ps.executeQuery (); calling ? Not already preprocessed yet ?
there but I did not set a few question marks , ah, can not call it.
I just simply want to know what type these few question marks and names it ~ ~ ~
------ For reference only --------------- ------------------------
I'm afraid your expectations to be dashed . . .
------ For reference only -------------------------------------- -
that ParameterMetaData no way to use this class ? Not always be able to know which database table column names and types , and I think this program is to find out the column names and types , so as to make the code more flexible ah
------ For reference only - --------------------------------------
to know the database table column names and types actually simple, you just need to perform :
Select * From Table
Then you can get to the inside from the ResultSet :
ResultSetMetaData meta = rs.getMetaData ();
------ For reference only --------------- ------------------------
anthracene amount finally I chose ResultSetMetaData, but I wanted to know this oracle can not really use ParameterMetaData What kind
------ For reference only ------------------------------------ ---
I have encountered this problem, I use oracle11g hey ~ ~ Chuan Chi podcast always used with mysql
------ For reference only ---------------- -----------------------
use ojdbc7.jar and JDK 7 can .

没有评论:

发表评论