这个是连接数据库代码
package utli;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.plaf.synth.SynthStyle;
public class Tool {
//获取与数据库的连接
public static Connection getConn() {
Connection conn=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "123456");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
//关闭数据库的连接
public static void close(Connection conn,PreparedStatement psmt) {
try {
if (conn!=null) {
conn.close();
}
if (psmt!=null) {
psmt.close();
}
} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String[] args) {
Connection conn=Tool.getConn();
if (conn!=null) {
System.out.println("连接成功");
}else {
System.out.println("连接失败");
}
}
}
报错信息
Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:ORCL
这个怎么解决各位da'l