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