Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2007, 11:24 AM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default why can't i compile this java file?

hi,im a beginer in java programming, need your help please..
:)

why can't i compile the 'ControlUser.java' file below?

there are two files
1st file : Mahasiswa.java
---------------------------------
package model.bean;
public class Mahasiswa
{
private String nim;
private String nama;

public Mahasiswa() {}

public Mahasiswa(String nim, String nama)
{
setNim(nim);
setNama(nama);
}

public void setNim(String n)
{
nim = n;
}

public void setNama(String n)
{
nama = n;
}

public String getNim()
{
return nim;
}

public String getNama()
{
return nama;
}
}

2nd file :ControlUser.java
------------------------------------------
package model;
import model.bean.Mahasiswa;
import java.sql.*;
import java.util.Vector;

public class ControlUser {

private String dbPath;
Connection con = null;
Statement st = null;

public ControlUser(String db){
dbPath = db;
}

//koneksi ke database

public void connectDb(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:driver={Mic rosoft Access Driver (*.mdb)};DBQ="+dbPath);
st = con.createStatement(1004,1008);
}catch(Exception e){ e.printStackTrace();}
}
public void closeDb(){
try{
st.close();
con.close();
}catch(Exception e){ e.printStackTrace();}
}

//ambil data mahasiswa dari database
public Mahasiswa [] loadMahasiswa(String query)
{
try{
connectDb();
ResultSet rs = st.executeQuery(query);
Vector <Mahasiswa> v = new Vector <Mahasiswa>();
while (rs.next()){
Mahasiswa temp = new Mahasiswa(rs.getString("nim"), rs.getString("nama"));
v.add(temp);
}
Mahasiswa [] arr = new Mahasiswa[v.size()];
v.toArray(arr);
rs.close();
closeDb();
return arr;
}catch(Exception e){e.printStackTrace();}
return null;
}
}
-------------------------------------------

thanx for your answer :)

 
Old June 11th, 2007, 08:03 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

Try the following syntax to compile the code
1. Go to the directory where your .java files were placed and try the following command

javac -d . *.java

-d tells the compiler to create folder structure according to the package structure and place the class file in that directory.
And the '.' says that the directories should be created in the current directory.
*.java to compile all java files.

Hope it solves your problem.

NOTE: you need to have java 1.5 to use generic objects.

Regards,
Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
can't get dll file to compile stevecist ASP.NET 1.0 and 1.1 Basics 3 January 2nd, 2007 01:10 PM
External file compile to run petermail Visual Studio 2005 2 September 6th, 2006 05:08 AM
How to compile C# file - Please get me started gau404 C# 2 November 12th, 2005 05:29 AM
Compile Java classes to EXE vb_programmer Java GUI 7 December 14th, 2004 08:16 AM
My Java program won't compile emilaghayev JSP Basics 0 October 21st, 2003 06:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.