A
A
alpa_kz2017-05-12 21:31:24
Oracle
alpa_kz, 2017-05-12 21:31:24

How to connect Java with Oracle?

How to connect Java with Oracle, if Oracle is installed on a virtual machine, and eclipse java on windows 10,
the jdbc driver is connected. When connecting, it gives the error "java.sql.SQLException: Invalid URL specified". I looked for this error, I did not find a normal answer in Google. So I thought what am I doing wrong??? Tell me please?

packageOracle;

import java.sql.*;
public class connect {
public static void main(String[] args){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:[email protected]:1521:orcl","system","Oracle");
Statement st = con.createStatement();
String sql="select * from jobs";
ResultSet rs = st.executeQuery(sql);
while(rs.next())
System.out.println(rs.getString(20)+" "+rs.getString(30));
con.close();
}
catch(Exception e){
System.out.println(e);
}
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
ferasinka, 2017-05-12
@alpa_kz

After port try slash
/stackoverflow.com/questions/4832056/java-jdbc-how-...

Thin-style Service Name Syntax
Thin-style service names are supported only by the JDBC Thin driver. The syntax is:
@//host_name:port_number/service_name
For example:
jdbc:oracle:thin:scott/[email protected]//myhost:1521/myservicename

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question