<%@ page language="java" import="java.sql.*" errorPage="" %>
<%
Connection conn = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
conn = DriverManager.getConnection("jdbc:odbc:mydsn","a", "a");
PreparedStatement psInsertRecord=null;
String sqlInsertRecord=null;
String dt=request.getParameter("datum1");
String Name=request.getParameter("Name");
try
{
sqlInsertRecord="insert into ATT (Date, Name) values(?,?)";
psInsertRecord=conn.prepareStatement(sqlInsertRecord);
psInsertRecord.setString(1,dt);
psInsertRecord.setString(2,Name);
psInsertRecord.executeUpdate();
}
catch(Exception e)
{
out.println("Unable to connect to the database");
}
try{
if(psInsertRecord!=null)
{
psInsertRecord.close();
}
if(conn!=null)
{
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</head>
<body>
<h3><center>Data saved successfully.<center><h3>
</body>
</html>
I am getting the following output:"Unable to connect to the database"
Papitha Murugan 0 Newbie Poster
Stefano Mtangoo 455 Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.