Connection to Oracle Database with Java -


i can't connect oracle database server. code :

import java.util.*; import java.sql.*; import java.io.ioexception;  public class knigi { public static void main(string[] args) {     string baza_driver="oracle.jdbc.driver.oracledriver";   string baza_string="jdbc:oracle:thin:@localhost:1521:";   string baza_username="knigi";   string baza_password="knigi";    locale.setdefault(locale.english); // vazhno e bidejkji oracle treba da znae kakvi poraki da pojavuva    try {       driver driver = (driver)class.forname(baza_driver).newinstance();        connection conn = drivermanager.getconnection(baza_string,baza_username,baza_password);        preparedstatement statement = conn.preparestatement("select * zhanrovi");       resultset zhanrovi = statement.executequery();       boolean isempty = !zhanrovi.next();       boolean hasdata = !isempty;       while (hasdata) {         system.out.println("zhanr: "+zhanrovi.getstring("zh_ime"));          preparedstatement statement2 =             conn.preparestatement("select * knigi zh_br = ?");         statement2.setint(1,zhanrovi.getint("zh_br"));         resultset knigi = statement2.executequery();         boolean isempty2 = !knigi.next();         boolean hasdata2 = !isempty2;         if (isempty2) {           system.out.println("      - nema knigi");         } else {           system.out.println("      - knigi:");         };         while (hasdata2) {           system.out.println(             "                 " +             knigi.getstring("isbn") +             " - " +             knigi.getstring("naslov")+" ");           hasdata2=knigi.next();         }         knigi.close();         hasdata=zhanrovi.next();       }       zhanrovi.close();       conn.close();     } catch (exception e) {       system.out.println(e);     } }  } 

and getting message:

java.sql.sqlexception: io exception: connection refused(description=(tmp=)(vsnnum=186646784)(err=12504)(error_stack=(error=(code=12504)(emfi=4))(error=(code=12504)(emfi=4)))) 

in school, example works. problem??

try this, might

  jdbc:oracle:thin://<host>:<port>/<service_name> 

service_name=sid of database, orcl.

cheers,


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -