【问题标题】:Not getting connection from ms access in jsp没有从jsp中的ms访问获得连接
【发布时间】:2013-07-10 17:16:11
【问题描述】:

我正在尝试在数据库中插入一些数据。但是出了点问题,但首先让我告诉你什么是对的:

我的 ms access dsn 在没有 jsp 的情况下运行良好,我可以使用简单的 java 程序插入数据。

Apache 正在运行一半的代码,而其他文件正在运行。 我没有收到任何错误消息......它甚至没有打印 try catch 消息。

代码如下:

    <html>
    <body>
    <%@ page import="java.sql.*"%>
    <%
    String name=request.getParameter("name");
    int rno=Integer.parseInt(request.getParameter("rollno"));
    int marks=Integer.parseInt(request.getParameter("marks"));


    out.println(name+"\n");
    out.println(rno+"\n");
    out.println(marks+"\n");
  //till here it works fine and print data 
    try{
    out.println("this too gettiing right");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    out.println("even this line is also getting printed");

    Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");
    out.println("But NOt this line"); 

    PreparedStatement ps=con.prepareStatement("insert in student values(?,?,?)");
    out.println("afte connection");
    ps.setInt(1,rno);
    ps.setString(2,name);
    ps.setInt(3,marks);
    int i=ps.executeUpdate();
    if(i>0){out.println("inserted ");}
    else{out.println("not inserted");}
    ps.close();
    con.close();


    }
    catch(SQLException se)
   {
   System.out.println(se);
   }
   catch(ClassNotFoundException e)
   {
   System.out.println(e);
   }

  %>
 </body>
 </html>

请帮我看看这里出了什么问题

【问题讨论】:

  • 你能发布你得到的异常吗?
  • 我没有收到任何异常消息。此代码仅生成此输出“anuj 89 2323 this too gettiing right even this line is also getting printing”

标签: jsp ms-access jdbc connection


【解决方案1】:

您需要对 jsp 代码进行几处更改。

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=myDB.mdb;";
Connection conn = DriverManager.getConnection(database, "username", "password");

也可以看看this

【讨论】:

  • 我做了这些更改,但我仍然得到相同的东西..连接后没有错误也没有执行,你希望我在你给出的链接中注意什么......(你的意思是模块化吗?还是别的什么?)
  • 我在 netbeans 中尝试了相同的代码及其工作......那么为什么它不能使用记事本与 appache 一起工作?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
  • 2019-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
相关资源
最近更新 更多