Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Database Connectivity

 
kumar prabhakar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timothy Kersha Akura,
Your post was moved to a new topic.
 
kumar prabhakar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added ojdbc6.jar to the classpath,now the code works with driver jdbcracle:driver:OracleDriver .
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic