This week's book giveaway is in the Cloud forum.
We're giving away four copies of The Business Blockchain and have William Mougayar on-line!
See this thread for details.
Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access oracle database from java application??

 
Tom Barns
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a sample code to access oracle database,do I need to import any packages?or do i need
to put anything in my classpath?I'm just new to do this.
please any help with it.
thanks alot.
sample code:
import java.sql.*;
import java.net.*;
public class ConnectToDatabase
{
public static void main(String a[])
{
try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc racle:thin:@aqdp004:1521:tls1";
Connection connection =
DriverManager.getConnection(url, "fmc", "password");
Statement st = connection.createStatement();
ResultSet result = st.executeQuery("SELECT * FROM ........ ");
while(result.next())
{
String s = result.getString(1);
System.out.println(s);
int b = result.getRow();
}

}
catch(ClassNotFoundException e)
{
}
catch (SQLException e)
{
}

}
}
 
Julio Lopez
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't know what error you are getting but, make sure the .jar or .zip file which contains the Oracle JDBC driver files is in your classpath. If it is not add it and it may require a reboot.
Julio Lopez
M-Group Systems
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic