Re: JDBC connection error
Quote:
Originally Posted by
nrao
Hi iam recieving error for my code for JDBC please help me
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at jdbcstatements.JDBCConnection.main(JDBCConnection. java:17)
my code
Code java:
package jdbcstatements;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class JDBCConnection {
public static void main(String[]args)
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection con=DriverManager.getConnection( url, "scott", "tiger");
System.out.println("connection created");
Statement db_statement = con.createStatement();
db_statement.executeUpdate
("create table employee { int id, char(50) name };");
con.commit();
ResultSet result = db_statement.executeQuery
("select * from employee");
while (result.next() )
{
// Use the getInt method to obtain emp. id
System.out.println ("ID : " + result.getInt("ID"));
// Use the getString method to obtain emp. name
System.out.println ("Name : " + result.getString("Name"));
System.out.println ();
}
} catch(Exception e){e.printStackTrace();}
}
}
Thrown when an application tries to load in a class through its string name using:
* The forName method in class Class.
* The findSystemClass method in class ClassLoader .
* The loadClass method in class ClassLoader.
but no definition for the class with the specified name could be found.
Re: JDBC connection error
i didnt get you what exactly is the problem please help me
Re: JDBC connection error
I must admit that I don't know much about networking, but it appears, from looking up the Class forName(String exp) method, that your forName(exp) cannot find that class.
Maybe you have a typo there.
Class (Java 2 Platform SE 5.0)
Also, maybe you haven't initialized it.
Re: JDBC connection error
This is a very common problem to JDBC newcomers. You must 1) download the driver (a .jar file you can get specific for your database) and 2) place the driver on your classpath.
Re: JDBC connection error
thank you copeg .I have downloaded jar and connection has been created but the Statement is not working
please help me.Iam getting this error
connection created
java.sql.SQLException: Non supported SQL92 token at position: 27: int
at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:146)
at oracle.jdbc.driver.OracleSql.handleToken(OracleSql .java:1165)
at oracle.jdbc.driver.OracleSql.handleODBC(OracleSql. java:1064)
at oracle.jdbc.driver.OracleSql.parse(OracleSql.java: 984)
at oracle.jdbc.driver.OracleSql.getSql(OracleSql.java :312)
at oracle.jdbc.driver.OracleSql.getSqlBytes(OracleSql .java:557)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStateme nt.java:193)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4C Statement.java:946)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTi meout(OracleStatement.java:1168)
at oracle.jdbc.driver.OracleStatement.executeUpdateIn ternal(OracleStatement.java:1614)
at oracle.jdbc.driver.OracleStatement.executeUpdate(O racleStatement.java:1579)
at jdbcstatements.JDBCConnection.main(JDBCConnection. java:24)
Re: JDBC connection error
This is an SQL error and not a java error.
Code :
db_statement.executeUpdate("create table employee { int id, char(50) name };");
The syntax is wrong. See the syntax for creating tables in SQL: SQL Create Table Statement. Notably, the brackets vs parenthesis.
Re: JDBC connection error
Thank you copeg its working