| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7315 人关注过本帖
标题:java代码连接Oracle数据库出错,求解,以下是错误信息
只看楼主 加入收藏
bcyu
Rank: 2
等 级:论坛游民
帖 子:39
专家分:56
注 册:2011-5-9
结帖率:100%
收藏
已结贴  问题点数:100 回复次数:5 
java代码连接Oracle数据库出错,求解,以下是错误信息
import java.sql.*;

public class Test {
    public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
    public static final String DBURL = "jdbc:oracle:thin:@localhost:1158:mldn" ;
    public static final String DBUSER = "scott" ;
    public static final String DBPASS = "tiger" ;
   
    public static void main(String[] args) {
        Connection conn = getConnection();
        if (conn != null) {
            System.out.println("success!");
        } else {
            System.out.println("error!");
        }
    }
   
    public static Connection getConnection() {
        Connection conn = null;
        
        try {
            Class.forName(DBDRIVER);
        } catch (ClassNotFoundException e) {
        //    e.printStackTrace();
        }
        
        try {
            conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        return conn;
    }
}

java.sql.SQLException: Got minus one from a read call
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at Test.getConnection(Test.java:28)
    at Test.main(Test.java:10)
Caused by: Got minus one from a read call
    at (Packet.java:285)
    at (NSProtocol.java:286)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
    ... 8 more
error!


搜索更多相关主题的帖子: java 数据库 Oracle 错误信息 
2011-08-12 00:48
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:5 
顶顶    高分贴
2011-08-12 12:46
bcyu
Rank: 2
等 级:论坛游民
帖 子:39
专家分:56
注 册:2011-5-9
收藏
得分:0 
帮忙回答啊,朋友们》。。。
2011-08-12 13:56
shimin198909
Rank: 2
等 级:论坛游民
帖 子:10
专家分:90
注 册:2011-8-12
收藏
得分:70 
package com.ambow;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import oracle.sql.DATE;

public class InsertStuBase {
     
        private String url="jdbc:oracle:thin:@localhost:1521:XE";
        private String user="shimin";
        private String password="shimin";
        //public void insertStud(int USERID,String NAME,String PASSWD,String PHONE,String EMAIL,String REG_DATE){
        public void insertStud(String EMAIL,int USERID){
            Connection conn=null;
            Statement stmt=null;
            try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
               
                conn = DriverManager.getConnection(url, user, password);
               
                stmt = conn.createStatement();
                //String sqlStr = "insert into USERS(USERID,NAME,PASSWD,PHONE,EMAIL,REG_DATE) " +
                //"values(" +USERID+",'"+NAME+"','"+PASSWD+"','"+PHONE+"','"+EMAIL+"',to_date('"+REG_DATE+"','yyyy-mm-dd'))";
                //String sqlStr="delete  from users where userid ="+USERID;
                  String sqlStr="update users set email='"+EMAIL+"' where userid="+USERID;
                int resNum = stmt.executeUpdate(sqlStr);
                if(resNum>0){
                    System.out.println("修改成功!");
                }else{
                    System.out.println("修改失败!");
                }
               
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                stmt.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
        }
     }
        public static void main(String[]args){
         InsertStuBase c=new InsertStuBase();
        
 

         c.insertStud("357509541@,2);
     }  
   
}
2011-08-12 15:53
wzh545394622
Rank: 6Rank: 6
等 级:侠之大者
帖 子:60
专家分:410
注 册:2009-10-7
收藏
得分:25 
话说oracle的端口不是1158吧,好像是1521吧!!!
2011-08-13 01:34
bcyu
Rank: 2
等 级:论坛游民
帖 子:39
专家分:56
注 册:2011-5-9
收藏
得分:0 
嗯嗯,谢谢各位,以解决......
2011-08-13 19:30
快速回复:java代码连接Oracle数据库出错,求解,以下是错误信息
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018396 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved