Hi everybody. I'm studying a short
java program. This program is using an URL connection. I believe, this code is connect to database using TCP/IP. I was drag the database to my Computer for accessing the data with a standalone system. Can I change this URL code to standalone system?How?
Thanks...
import java.sql.*; //import all the
JDBC classes
public class Data { //1
String subjek[] = new String[100] ;
int bil=0;
public Data() {//2
String URL = "jdbc:ids://161.142.43.224:12/conn?dsn='IDSExamples'"; String username = "";
String password = "";
try { //3
Class.forName("ids.sql.IDSDriver").newInstance();
} //3
catch (Exception e) { //4
System.out.println("Failed to load JDBC/ODBC driver."); return; } //4
Statement stmt = null;
Connection con=null;
try { //5
con = DriverManager.getConnection (URL);
stmt = con.createStatement();
} //5
catch (Exception e) { //6
System.err.println("problems connecting Data to "+URL);
} //6
try { //7 execute SQL commands to create table, insert data
String query = "SELECT * FROM Kursus Where Kod Like 'T%' ";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {//8
//System.out.println("Kod Kursus: " +rs.getString("Kod")+ " Nama: " +rs.getString("Nama") );
subjek[bil] = new String(rs.getString("Kod"));
bil++;
}//8
rs.close();
stmt.close();
con.close();
} //7
catch (Exception e) { //9
System.err.println("problems with SQL sent Data to "+URL+": "+e.getMessage()); }//9
}//2
public int getbil() {
return bil;
}
public String[] getsubjek() {
return subjek;
}
public static void main(String[] args) {
int bil=0;
int i=0;
String subjek[];
Data cuba = new Data();
bil = cuba.getbil();
subjek = cuba.getsubjek();
System.out.println("Bilangan semua tempat ialah : " + bil);
while (i<bil) {
System.out.println("Kod subjek: " + subjek[i]);
i++;
}
}
}//1