• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in creating Instance

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i have following program Which connects to database

import java.io.*;
import java.sql.*;
import java.util.Vector;

public class Database
{
public Connection Conn;
Statement st;

public Database()
{
try
{
String url = "jdbc ostgresql://192.168.0.124:5432/test";
DriverManager.registerDriver(new org.postgresql.Driver());
Conn = DriverManager.getConnection(url,"postgres","");
}
catch (SQLException ex )
{
System.out.println("Exception in Database.Database moblog " + ex );
}
catch (Exception genex)
{
System.out.println("Exception in Database " + genex );
}
}

public Connection getConn()
{
return Conn;
}

public ResultSet Select(String SQLStatement)
{
ResultSet result=null;
try {
st=(Statement) getConn().createStatement();
result=(ResultSet) st.executeQuery(SQLStatement);
if (result.isBeforeFirst()==false)
return null;
} catch (SQLException ex) {
return null;
}
return result;
}

public boolean Execute(String SQLStatement) {
try {
st=(Statement) getConn().createStatement();
if(st.executeUpdate(SQLStatement) >=0)
return true;
st.close();
} catch (SQLException ex) {
return false;
}
return true;
}

public void CloseConn()
{
try
{
Conn.close();
}
catch (SQLException ex ){ }
}

public static void main(String args[])
{
try
{
Database db=new Database();
Statement st=(db.getConn()).createStatement();
ResultSet result=st.executeQuery("select * from account limit 10");
while(result.next()) {
System.out.println("values "+result.getString(1)+"="+result.getString(2));
}
if(result!=null)
result.close();
if(db!=null)
db.CloseConn();
}
catch(SQLException e)
{
System.out.println(e);
}
}
}

but when i create instance of Database in following program i get compilation error saying cannot resolve symbol

import java.sql.*;

import java.lang.*;



public class TestInstance

{

public String retData(int count)

{

String password = null;

try

{

System.out.println("Before Instantiation ");
Database db = new Database();

Passwd psw = new Passwd();

password = psw.generatePasswd(count);

System.out.println("After Instantiation ");

}catch(Exception ex){

System.out.println("Exception in Database");

}

return password;

}



public static void main(String[] args)

{

Passwd psw = new Passwd();

String pass = psw.generatePasswd(8);

System.out.println("Hello ur passwd is "+pass);

TestInstance ti = new TestInstance();

String s = ti.retData(8);

System.out.println("Hello ur passwd is "+s);

}

}


and when i compile this code on other machine it works fine.

what could be the solution for this please help me
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a word: CLASSPATH. You don't tell us which symbol the compiler can't resolve, but I'd suspect it was this: org.postgresql.Driver. You need to make sure that your Driver class is in the CLASSPATH.
 
Nilesh Joshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi n thanx for instant reply, i m not getting any problem in Database file where i actually make a connection with database, the problem is in other program when i try to make an instance of Database file.

i get error at

Database db = new Database();
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, are you saying that the code which complains it "cannot resolve symbol" is not the code you posted!?

Can you show use the code and the exception stack trace?
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That may be because, The DataBase class is not visible in the calling class. Try including the DataBase class in the imports section of the calling class.
 
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic