当前位置: 技术问答>java相关
数据库连接的错误?
来源: 互联网 发布时间:2015-10-25
本文导语: Class.forName("oracle.jdbc.driver.OracleDriver"); url = jdbc:oracle:thin:@192.168.0.4:1521:wap username = system password = manager conn.DriverManager.getConnection(url,username,password); 出现以下错误: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=15 0999040)(ERR...
Class.forName("oracle.jdbc.driver.OracleDriver");
url = jdbc:oracle:thin:@192.168.0.4:1521:wap
username = system
password = manager
conn.DriverManager.getConnection(url,username,password);
出现以下错误:
Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=15
0999040)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
请问这一般是什么造成的呢?
或者说我在哪一步出现问题了?
|
/*
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC THIN driver. See the same program in the
* oci8 samples directory to see how to use the other drivers.
*/
// You need to import the java.sql package to use JDBC
import java.sql.*;
class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@dlsun511:1721:dbms733",
"scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
这是oracle 自带的例子。
你的问题,1 服务名是不是wap.2 确定system 的密码是不是被修改了。3 确定1521端口是不是被占用了。
username = system
password = manager-----------为什么不大引号?
username = "system"
password = "manager"
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC THIN driver. See the same program in the
* oci8 samples directory to see how to use the other drivers.
*/
// You need to import the java.sql package to use JDBC
import java.sql.*;
class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@dlsun511:1721:dbms733",
"scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
这是oracle 自带的例子。
你的问题,1 服务名是不是wap.2 确定system 的密码是不是被修改了。3 确定1521端口是不是被占用了。
username = system
password = manager-----------为什么不大引号?
username = "system"
password = "manager"
|
oracle服务端tns没有起来
检查你的wap,看是否正常
检查你的wap,看是否正常
|
sqlplus是oracle服务器上的吗?
你用oracle自带的测试工具测试一下呢
你用oracle自带的测试工具测试一下呢
|
你到数据库上用netstat -a命令看一下你的1521端口有没有起来
|
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection dbCon = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.4:1521:wap", "system", "manager");
Connection dbCon = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.4:1521:wap", "system", "manager");
|
你的数据库监听没有起来,检查一下监听吧在服务中