jdbc连接数据库连不上 5C

导包 ojdbc6.jar
jdk 1.7.0_0.09
oracle版本
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

//jdbc类
public class jdbc {

public static void main(String[]args){
    Connection conn=null;
    Statement state=null;
    try {
        Class.forName("oracle.jdbc.OracleDriver");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("11");
    }

    try {
        conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","QMXC_PROJECT","qmxc");
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("22");
    }

    try {
        state=conn.createStatement();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("33");
    }

    try {
        state.execute("insert into wen values (1,'wen','12','nan'");
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("sql语句错误");
    }
}

}

//报错
java.sql.SQLException: Undefined Error
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.(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:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at jdbc.main(jdbc.java:21)
Caused by: oracle.net.ns.NetException: Undefined Error
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:385)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more

2个回答

报错是网络错误,看下防火墙是否允许了oracle的端口,还有ip地址对不对,还有服务器是否正常运行

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
jdbc连接数据库jdbc连接数据库
jdbc连接数据库 jdbc连接数据库 jdbc连接数据库 jdbc连接数据库 jdbc连接数据库
连接数据库连不上
我用的数据库是SQL Server 2005,以前用的是Windows身份验证,后来我换成了混合验证,并启用了sa 用户,密码设成了8888.rnrn下面是运行程序时的错误信息:rn时间:2007-8-13 11:01:30rnrn系统版本号:1.0.0.1rnrn系统错误信息:已成功与服务器建立连接,但是在登录过程中发生错误。 (provider: 命名管道提供程序, error: 0 - 管道的另一端上无任何进程。)rnrn连接字符串为:rnServer=192.168.3.111;DataBase=ERP-QUANCHENG-REDBULL;uid=sa;pwd=8888;rnrn如果把连接字符串换成:rnServer=.;DataBase=ERP-QUANCHENG-REDBULL;uid=sa;pwd=8888;rnServer=(local);DataBase=ERP-QUANCHENG-REDBULL;uid=sa;pwd=8888;rn就不会出错,我已设置了数据库允许远程连接,为什么还会出这种错?数据库哪里设错了?
jdbc数据源连接数据库和jdbc连接数据库
1. 配置web 找到配置context.xml ...
JDBC复习之JDBC连接数据库
今日目录        1、JDBC连接数据库步骤        2、在项目里配置数据库驱动        3、加载数据驱动        4、连接及关闭数据库一、JDBC连接数据库步骤        1、加载驱动        2、连接数据库        3、使用语句操作数据库        4、关闭数据库连接,释放资源二、在项目里配置数据库驱动第一步:file -> Project S...
JSP连接数据库,怎么连不上?
代码:rnrnrn New Page 1rnrnrn<%@ page language="java" import="java.sql.*" contentType="text/html;charSet=gb2312"%>rn<%String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";rn String url="jdbc:microsoft:sqlserver://zhy:1433;DatabaseName=pubs"; rn String user="sa"; rn String password=""; rn String sqlstr="select * from jobs";rn Connection conn=null;rn Statement lstmt=null;rn ResultSet rs=null;rn Class.forName(driver).newInstance();rn tryrn rn conn=DriverManager.getConnection(url,user,password);rn rn catch(Exception e)rn out.println(e.toString());rn rn tryrn lstmt=conn.createStatement();rn rs=lstmt.executeQuery(sqlstr);rn rn catch(Exception e)rn out.println(e.toString());rn rn while (rs.next())rn out.println(""+rs.getString("job_desc")+"");rn rn rs.close();rn lstmt.close(); rn conn.close();rn%>rn%>rnrnrnrnrnrnrn这个问题已经有4、5天未解决了。那就是从JSP中连接sql server数据库,详细资料如下:rn jdk:jdk1.40;rn apache:apache_2.0.43;rn tomcat:tomcat-4.1.24;rn sql server 2000 driver for jdbc;rn 安装好以上组件后,输入http://localhost和http://localhost:8080均可见到正确的运行画面。并且已经将sql server 2000 driver for jdbc中三个jar文件:rnmabase.jar、msutil.jar、mssqlserver.jar拷贝到jdk\bin目录下,相应的path和classpath均已设置,但是一运行以下代码就出现以下exceptionrnrnrnorg.apache.jasper.JasperException: com.microsoft.jdbc.sqlserver.SQLServerDriverrn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)rn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)rn at java.lang.Thread.run(Thread.java:536)rnrnrnroot cause rnrnjavax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriverrn at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)rn at org.apache.jsp.query_jsp._jspService(query_jsp.java:86)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)rn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)rn at java.lang.Thread.run(Thread.java:536)
spring连接数据库一直连不上
最近用ssm时来凝结数据库,做了几百遍的,但一直连不上数据库,加载资源文件后,执行总报com.mchange.v2.c3p0.DriverManagerDataSource] - Could not load driverClass com.mysql.jdbc.Driver 错误,后来发现db.properties文件中db.driverClass=com.mysql.jdbc.Driver
JDBC(二)——JDBC连接数据库
JDBC连接数据库步骤: 1.加载驱动: 第一步:在项目里配置数据库驱动; 首先新建一个类qudong;然后配置驱动: (MySql驱动实现类:mysql-connector-java-5.1.36下载链接:https://pan.baidu.com/s/1OFNqp03MR0_cICKqYYPXWQ); 右击项目-&amp;gt;Build Path-&amp;gt;Configure Build P...
jdbc入门、jdbc连接数据库
一、jdbc入门 1、在此之前操作数据(之前的数据库博客中) 1)通过mysql的客户端工具,登录数据库服务器 (mysql -u root -p 密码) 2)编写sql语句 3)发送sql语句到数据库服务器执行 2、什么是jdbc 1)没有jdbc时如何用java代码操作数据库: 2)jdbc出现之后呢?
连接数据库连不上怎么回事?
[code=C#]rn public class DBManagerrn rn public DBManager()rn rnrn rn public static SqlConnection cn ;rn public static string connectionString = ConfigurationManager.AppSettings["CONN"];rnrn public static SqlConnection open()rn rn cn = new SqlConnection(connectionString);rn if(cn.State==ConnectionState.Closed)rn rn cn.Open();rn rn return cn;rn rnrn public static void close()rn rn cn.Close();rn rn rnrnrn后面是调用rnrnpublic static void Delete(string id)rn rn tryrn rn DBManager.open();//这句话就报错了怎么回事?rn SqlCommand cm = DBManager.cn.CreateCommand();rn cm.CommandType = CommandType.StoredProcedure;rn cm.CommandText = "DeleteEqumentBaseID";rn cm.Parameters.AddWithValue("@ID",id);rn cm.ExecuteNonQuery();rn rn catch (SqlException ex)rn rn throw new Exception(ex.Message);rn rn catch (Exception ex)rn rn throw new Exception(ex.Message);rn rn finallyrn rn DBManager.close();rn rn rn[/code]
连接数据库时总连不上
我在ASP.NET中建个Web应用程序,调试这段代码:rnrnstring sqlcmd = "select EmployeeID,FirstName from Employees where EmployeeID = 5";rnSqlConnection myConnection = new SqlConnection();rnmyConnection.ConnectionString = "Data Source = localhost;Initial Catalog = Northwind;Integrated Security =SSPI";rnqlCommand cmd = new SqlCommand(sqlcmd,myConnection);rnSqlDataReader reader;rnmyConnection.Open();rnreader = cmd.ExecuteReader();rnreader.Read();rndisplayer.Text = reader.GetInt32(0).ToString() + " "+ reader.GetString(1);rnreader.Close();rnmyConnection.Close();rnrn得到结果:rn用户 'DATABASE\ASPNET' 登录失败。rn数据库是SQL2000自带的Northwind。rn奇怪的是把这段代码拷到新建的C#应用程序里运行就没问题。rn哪位高手帮忙解决一下,谢谢。
c#连接数据库 连不上好像
SqlConnection con = new SqlConnection(@"Data Source=.;initial catalog=teacher;user id=sa;password=1");rn
JDBC连接数据库
一、简单的连接 创建一个DBConnectionManager类,方便使用。
连接数据库JDBC
数据库的连接代码 package com.lovo.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class TestMain {
jdbc连接数据库
⑴  加载连接的数据库的驱动  在写代码之前,我们知道所写的代码可能会抛出异常,所以我们要将代码try{}catch(){}住。  因为我用的是mysql,所以这里我只写了连接mysql的驱动,  Class.forName(com.mysql.jdbc.Driver);//将驱动类加载,  ⑵与数据库进行连接  Connection conn=DriverManager.getCon
jdbc 连接数据库
jdbc 连接数据库
连接数据库!jdbc
//统计student表中的男生数目rnString sql1 = "select count(*) from student where banji=' "+banjijComboBox.getSelectedItem().toString()+" ' and xingbie='男'; " ;rnrn//统计student表中的女生数目rnString sql2 = "select count(*) from student where banji='"+banjijComboBox.getSelectedItem().toString()+"' and xingbie='女';";rnrn//更新class中的男女数目的数据rnString sql3 = "update class set nan="+tjnan+",nv="+tjnv+" where mingcheng='"+banjijComboBox.getSelectedItem().toString()+" ';";rnrn全的代码:rnint tjnan=0,tjnv=0; //定义男生数和女生数 rn //统计男生数量rn try rn Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");rn String url1 = "jdbc:odbc:stu";rn Connection conn1 = DriverManager.getConnection(url1);rn Statement stat1 = conn1.createStatement();rn String sql1 = "select count(*) from student where banji=' "+banjijComboBox.getSelectedItem().toString()+" ' and xingbie='男'; " ;rn ResultSet rSet1=stat1.executeQuery(sql1);rn rSet1.next();rn tjnan=rSet1.getInt(1);rn jbjg.setText("统计男生数成功");rn conn1.close();rn catch(java.lang.Exception exec) rn jbjg.setText("统计男生数失败!");rn rn rn //统计女生数rn try rn Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");rn String url2 = "jdbc:odbc:stu";rn Connection conn2 = DriverManager.getConnection(url2);rn Statement stat2 = conn2.createStatement();rn String sql2 = "select count(*) from student where banji='"+banjijComboBox.getSelectedItem().toString()+"' and xingbie='女';";rn ResultSet rSet2=stat2.executeQuery(sql2);rn rSet2.next();rn tjnv=rSet2.getInt(1);rn jbjg.setText("统计女生数成功");rn conn2.close();rn catch(java.lang.Exception exec) rn jbjg.setText("统计女生数失败");rn rn rn //修改班级中的男生和女生数rn try rn Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");rn String url3 = "jdbc:odbc:stu";rn Connection conn3 = DriverManager.getConnection(url3);rn Statement stat3 = conn3.createStatement();rn String sql3 = "update class set nan="+tjnan+",nv="+tjnv+" where mingcheng='"+banjijComboBox.getSelectedItem().toString()+" ';";rn int rowCount =stat3.executeUpdate(sql3);rn if (rowCount>0 )rn //jbjg.setText("修改班级中的男生和女生数-成功");rn rn conn3.close();rn catch(java.lang.Exception exec) rn // jbjg.setText("修改班级中的男生和女生数-失败");rn rn rnrn怎么改成合起来的阿!!rn//统计男生数目rn String sql1 ="select count(*) from student where banji='"rn +xuanzebanjijComboBox.getSelectedItem().toString()rn +"'and xingbie='男';";rn //统计女生数目rn String sql2 ="select count(*) from student where banji='"rn +xuanzebanjijComboBox.getSelectedItem().toString()rn +"'and xingbie='女';";rn Connection conn = null;rn rn try rn Class.forName(str);rn conn = DriverManager.getConnection(url);rn Statement stat = conn.createStatement();rn String sql = [color=#FF0000]"update class set nan=(select count(*) from student where banji='"rn +xuanzebanjijComboBox.getSelectedItem().toString()rn +"'and xingbie='男';),nv=(select count(*) from student where banji='"rn +xuanzebanjijComboBox.getSelectedItem().toString()rn +"'and xingbie='女';) where mingcheng='"rn + xuanzebanjijComboBox.getSelectedItem().toString()+"';";[/color] int rowCount =stat.executeUpdate(sql);rn if (rowCount >0)rn jbjg.setText("修改班级中的男女生数目成功!");rn rn conn.close();rn catch(Exception exec)rn jbjg.setText("修改班级中的男女生数目失败!");rn
JDBC 连接数据库
preparedstatement  和statement的区别: 参考:http://www.hudong.com/wiki/PreparedStatement 1: PreparedStatement是预先编译的语句,而Statement则不是预先编译的。当由于 PreparedStatement 对象已预编译过,所以其执行速度要快于 Statement 对象。2: PrepareStat...
Jdbc连接数据库
Jdbc是Oracle公司提供的一套接口 驱动:jdbc的实现类由数据库厂商提供 使用jdbc 导入驱动jar包 编码: 注册驱动 获取连接 编写sql 创建预编译语句的执行者 设置参数 执行sql语句 处理结果 释放资源 mysql数据库:** jdbc驱动的jar包 密码:p81k 下面是所有版本的 http://central.maven.org/maven2/my...
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法