Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to create SQL Connections String using JSP

843840May 28 2009 — edited Jun 15 2009
Hi, Dear I wrote sample Jsp program(Create a table and Inserted to Table) using SQLConnection
I got this Error, how to rectify please help me?

This is my Connection String
<%
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;

try
{
String url=java.sql.DriverManager.getConnection("jdbc:sqlserver://10.1.5.6:1433;Database=manickaraj;User=sa; Password=test*");
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}

if(request.getParameter("action") != null)
{
String CategoryName=request.getParameter("Category1");
String Description=request.getParameter("Description1");
String Status=request.getParameter("Status1");
stmt.executeUpdate("insert into Category(CategoryName,Description) values('"+CategoryName+"','"+Description+"','"+Status+"')");
rst=stmt.executeQuery("select * from Category");
}
%>


org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 5 in the jsp file: /CategoryAction.jsp
Generated servlet error:
C:\Documents and Settings\manickaraj\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\SampleJsp\org\apache\jsp\CategoryAction_jsp.java:61: incompatible types
found : java.sql.Connection
required: java.lang.String


An error occurred at line: 5 in the jsp file: /CategoryAction.jsp
Generated servlet error:
String url=java.sql.DriverManager.getConnection("jdbc:sqlserver://10.1.2.4:1433;Database=manickaraj;User=sa; Password=test*");
^
1 error



org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2009
Added on May 28 2009
13 comments
1,548 views