public static void baglanti(){
OracleDataSource ods;
//String driverName = "oracle.jdbc.driver.OracleDriver";
try {
ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@//aaaaaa:2122/XXXXX");
ods.setUser("aaaa");
ods.setPassword("aaaa");
Connection conn=ods.getConnection();
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("SELECT DESCRIPTION FROM example");
while (rs.next()) {
//rs.getString("ID");
System.out.println("DESC : "+rs.getString("1"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have an error my connection java from to oracle.user name ,password are correct but I couldn't connect to db.
Thanks.
解决方案
The way you use getString is wrong.
You can pass an index or the column label:
System.out.println("DESC : "+rs.getString(1));
or
System.out.println("DESC : "+rs.getString("description"));
you pass the index as a String and that's wrong.