aspose file tools*
The moose likes JDBC and the fly likes Java Database Connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java Database Connectivity" Watch "Java Database Connectivity" New topic
Author

Java Database Connectivity

kumar prabhakar
Greenhorn

Joined: Feb 27, 2012
Posts: 13
I am new to JDBC,I have added OJDB6_G.JAR to my classpath.But,still get the error

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Prabh>cd\

C:\>d:

D:\>javac Connect.java

D:\>java Connect
java.sql.SQLException: No suitable driver found for jdbcracle:thin:@loc alhost
:1521:xe
Driver loaded
Connected to the Oracle Database
java.lang.NullPointerException


D:\>
/////I am trying to connect to oracle 10g .
JAVA CODE:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Connect {

public static void main(String[] args) {

String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String cs="jdbcdbc:connect_oracle";
String user = "HR";
String pwd = "123";
String sqlstmt="INSERT INTO FIRST VALUES(1,'PRABHAKAR')";
Connection con = null;
Statement st = null;
try
{
Class.forName(driver);
con = DriverManager.getConnection("jdbcracle:thin:@loc alhost:1521:xe",user,pwd);

}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("Driver loaded");
try
{

System.out.println("Connected to the Oracle Database");
//st = con.createStatement();//creates a Statement object for sending SQL statements to the database.
//int updatecount=st.executeUpdate(sqlstmt);//return either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
//System.out.println(updatecount+" row inserted");
}
catch(Exception e)
{
System.out.println(e);
}
try
{
st.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}//main()
}//class()

Anyone can help me out...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Please UseCodeTags next time, and don't forget to add proper indentation.

Your problem is your driver. You're loading the ODBC driver class but try to connect using an Oracle connection String. You should load the Oracle driver class, which of course means you should include the driver JAR file to your class path.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Timothy Kersha Akura,
Your post was moved to a new topic.
kumar prabhakar
Greenhorn

Joined: Feb 27, 2012
Posts: 13
I have added ojdbc6.jar to the classpath,now the code works with driver jdbcracle:driver:OracleDriver .
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Database Connectivity