Problem with database connection
9 answers - 694 bytes -

hi, i have a problem, i'm using classes12.jar to connect to the oracle database. and i get this error
"Error connecting: java.sql.SQLException: Io exception: Got minus one from a read call"
i checked and every thing is allright(host,port,sid etc)
but still....
the code is:
String driver="oracle.jdbc.driver.OracleDriver";
String host = "localhost";
String dbName = "killaz";
String url="jdbc:oracle:thin:@"+host+":1521:"+dbName;
String username = "scott";
String password ="tiger";
Class.forName(driver);
Connection connection = DriverManager.getConnection(url,username,password) ;
help!
No.1 | | 229 bytes |
| 
seems everything ok but could u plz be more specific about ur problem and give more code where u r fetching records from the database as i think there must be some error in fetching data coz Every other thing is perfect otherwise
No.2 | | 2073 bytes |
| 
Originally posted by deep_ar78
seems everything ok but could u plz be more specific about ur problem and give more code where u r fetching records from the database as i think there must be some error in fetching data coz Every other thing is perfect otherwise
I'm just want to see if my connection with database is working, so this is the code :
public static void main(String[] args) {
String driver="oracle.jdbc.driver.OracleDriver";
String host = "localhost";
String dbName = "killaz";
//String url = DriverUtilities.makeURL(host, dbName, vendor);
String url="jdbc:oracle:thin:@"+host+":1521:"+dbName;
String username = "scott";
String password ="tiger";
showTable(driver, url, username, password);
}
public static void showTable(String driver,
String url,
String username,
String password) {
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url,username,password) ;
Statement statement = connection.createStatement();
String query = "SELECT * FROM emp;";
ResultSet resultSet = statement.executeQuery(query);
while(resultSet.next()) {
System.out.print(" " + resultSet.getInt(1));
System.out.print(" " + resultSet.getString(2));
System.out.print(" " + resultSet.getString(3));
System.out.print(" " + resultSet.getInt(4));
System.out.println(" " + resultSet.getInt(6));
System.out.println(" " + resultSet.getInt(7));
System.out.println(" " + resultSet.getInt(8));
}
} catch(ClassNotFoundException cnfe) {
System.err.println("Error loading driver: " + cnfe);
} catch(SQLException sqle) {
System.err.println("Error connecting: " + sqle);
}
}
No.3 | | 228 bytes |
| 
well the code is working fine on my machine and i cant guess now whats going wrong on ur machine...i would just say include both classes111.jar and classes12.jar in apache_home/common/lib and let see wut happens
Best of luck
No.4 | | 364 bytes |
| 
Originally posted by deep_ar78
well the code is working fine on my machine and i cant guess now whats going wrong on ur machine...i would just say include both classes111.jar and classes12.jar in apache_home/common/lib and let see wut happens
Best of luck
ok, thank u. someone told me that it is a problem with my LAN settings.
again, 10thx
No.5 | | 307 bytes |
| 
Hello there.
I have also the same problem with my SQL connection. The only difference between mine and Killaz is that I am using a Typical MySQL DB created in phpmyadmin and running on localhost.
Any suggestions?
Please reply here: http://www.dbforums.com/t974955.html
;)
No.6 | | 1545 bytes |
| 
Originally posted by deep_ar78
well the code is working fine on my machine and i cant guess now whats going wrong on ur machine...i would just say include both classes111.jar and classes12.jar in apache_home/common/lib and let see wut happens
Best of luck
Hi, I just come across your reply to the message describing a similar problem I have connecting to Oracle9i DB. I tried a couple of simple java files (Including the one you discussed here) to check connection to my newly locally installed Oracle9i DB, and I have two types of errors depending on the driver I use. Since I am new to Oracle could you please tell me where the problem area? Do I have to put something else in the Classpath in addition to classes.12.zip to make it work?
The errors I have:
1. Error connecting: java.sql.SQLException: Invalid Oracle URL specified
2. Exception in thread "main" java.sql.SQLException: Invalid Oracle URL specified
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:285)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriv er.java:203)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at RecordingOCI.main(RecordingOCI.java:8)
Any suggestion would be higly appreciated.
Thank you.
No.7 | | 71 bytes |
| 
Can you post the URL that you've used to connect to the Oracle DB?
No.8 | | 515 bytes |
| 
Originally posted by elitearuba
Can you post the URL that you've used to connect to the Oracle DB?
I've used this
("jdbc:oracle:oci9:@(description=(address=(host=dbse rver)(protocol=tcp)(port=1521)) connect_data=(sid=database)))", "scott", "tiger");
this
"jdbc:oracle:thin:@trianon:1521:local", "scott", "tiger",
and that
("jdbc:oracle:oci:@trianon", "scott", "tiger");
Also, I tried the one in the posted sample and got the same URL error.
trianon
No.9 | | 304 bytes |
| 
ok, thank u. someone told me that it is a problem with my LAN settings.
again, 10thx
Hi Killaz, I am getting the same "minus one" problem with my JDBC call. Can you please elaborate what sort of problem with LAN settings you faced and how you resolved it?
Thanks a lot.
Raj