用java连接oracle,在编译的时候出现这样的问题
SQLException:IO例外。 Got minus one from a red call
不知道是为什么,请帮我解决以下,谢谢!
代码是:
import java.sql.*;
import java.io.*;
import java.util.*;
import java.util.Date;public class oo
{
public static void main(String args[])
{
String url="jdbc:oracle:thin:@localhost:7778:tangming";
Connection con;
Statement stmt;
String query = "select PASSWORD from T_USER where USER_ID='00001'";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
con = DriverManager.getConnection(url, "jbuser", "abc");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
System.out.println("userinfromation");
while (rs.next())
{
String f = rs.getString("PASSWORD");
System.out.println(f); }
stmt.close();
con.close();
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
System.out.println("sorry ! could not connection with DB!!");
}
}
}
SQLException:IO例外。 Got minus one from a red call
不知道是为什么,请帮我解决以下,谢谢!
代码是:
import java.sql.*;
import java.io.*;
import java.util.*;
import java.util.Date;public class oo
{
public static void main(String args[])
{
String url="jdbc:oracle:thin:@localhost:7778:tangming";
Connection con;
Statement stmt;
String query = "select PASSWORD from T_USER where USER_ID='00001'";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
con = DriverManager.getConnection(url, "jbuser", "abc");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
System.out.println("userinfromation");
while (rs.next())
{
String f = rs.getString("PASSWORD");
System.out.println(f); }
stmt.close();
con.close();
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
System.out.println("sorry ! could not connection with DB!!");
}
}
}
不要在 while (rs.next()) {}里面定义String f = rs.getString("PASSWORD");在外面定义String f ="";
然后再到while 里面引用
2)String url="jdbc:oracle:thin:@localhost:7778:tangming";
这应该是连接本地的数据库。
如果连接服务器的数据库,localhost:7778: --〉服务器的ip 地址 :数据库的端口
这个是连本地数据库的错,不知道是怎么回事?
2)oralce 数据库的端口默认一般是 1521 ,而不是7778