I created a folder priya. Under that I created 2 folders connections and procedures.
Both folders have one java file.
The connection folder has a Connectionfactory.java file that gets the database connection and the procedure folder has a CreateSetPrice.java file that creates a stored procedure from database. The procedure sets a price.
The connection for database has to be taken from the ConnectionFactory.java in the other folder.
I set the classpath as set classpath = c:\priya\connections;c:\priya\procedures;
The ConnectionFactory file compiles.
The CreateSetPrice.java file has:
package procedures;
import java.sql.*;
import java.util.*;
import connections.*;
I copied both file codes from a book and the code is okay and compiles. The CreateSetPrice.java file however does not recognise the ConnectionFactory at all??
Error is: "package connections does not exist" and other error are related to it like "cannot resolve symbile Connectionfactory".
I think I set the classpath but I dont know what else to do ? Please help.
---------------------
Pasting the two files below for reference:
package procedures;
import java.sql.*;
import java.util.*;
import connections.*;
public class CreateSetPrice
{
public static void main(String args[])
{
Connection conn = null;
Statement stmt = null;
try
{
conn = ConnectionFactory.getConnection();
stmt = conn.createStatement();
String sql = "create or replace procedure set_price ("+
"+id in number,price in number)" + "as begin "+
"update recordings set listprice = price "+
"where recordingid = id; end;";
int result = stmt.executeUpdate(sql);
// result should return 0
System.out.println("Procedure created sucessfully");
}//try
catch(Exception e)
{
System.out.println("Procedure not created");
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
}//main
}
package connections;
import java.sql.*;
public class ConnectionFactory
{
private static ConnectionFactory ref = new ConnectionFactory();
//Constructor
private ConnectionFactory()
{
try
{
Class.forName("oracle.jdbc.odbc.OracleDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("Error: exception loading drivers");
}
}
public static Connection getConnection() throws SQLException
{
String url = "jdbc:oracle:thin:@wcsuds1.ctstateu.edu:1521:wprac";
return DriverManager.getConnection(url,"sys","featherstone");
}
public static void close(ResultSet rs)
{
try
{
rs.close();
}
catch(Exception e)
{
System.out.println("Exception ignored");
}
}
public static void close(Statement stmt)
{
try
{
stmt.close();
}
catch(Exception e)
{
System.out.println("Exception ignored");
}
}
public static void close(Connection conn)
{
try
{
conn.close();
}
catch(Exception e)
{
System.out.println("Exception ignored");
}
}
}
-
how to import own package in the java file? (5 messages)
- Posted by: priyanka shah
- Posted on: August 12 2002 11:18 EDT
Threaded Messages (5)
- how to import own package in the java file? by Frank Febbraro on August 12 2002 12:18 EDT
- how to import own package in the java file? by Web Master on August 12 2002 12:48 EDT
- how to import own package in the java file? by Web Master on August 12 2002 12:48 EDT
- how to import own package in the java file? by sean decor on August 12 2002 16:19 EDT
- how to import own package in the java file? by sean decor on August 12 2002 16:22 EDT
-
how to import own package in the java file?[ Go to top ]
- Posted by: Frank Febbraro
- Posted on: August 12 2002 12:18 EDT
- in response to priyanka shah
Try
import priya.connections.*; -
how to import own package in the java file?[ Go to top ]
- Posted by: Web Master
- Posted on: August 12 2002 12:48 EDT
- in response to priyanka shah
try taking the package names out of the classpath...
classpath = c:\priya
-
how to import own package in the java file?[ Go to top ]
- Posted by: Web Master
- Posted on: August 12 2002 12:48 EDT
- in response to priyanka shah
try taking the package names out of the classpath...
classpath = c:\priya
-
how to import own package in the java file?[ Go to top ]
- Posted by: sean decor
- Posted on: August 12 2002 16:19 EDT
- in response to priyanka shah
just put classpath to c:\priya
understand the basic here that u your class path has to point til the package and not include any of the folder names in ur package.
for a class myclass in package x.y.z with x, y,z being folders under C drive like c:\x\y\z\myclass.class. Then ur class path shd just have c and not c:\x\y\z.
I hope i didnt confuse u :)
-
how to import own package in the java file?[ Go to top ]
- Posted by: sean decor
- Posted on: August 12 2002 16:22 EDT
- in response to priyanka shah
also dont put ur sensitive code on a public site, specially ur database id and password ..