Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:55:29+00:00 2026-05-27T19:55:29+00:00

i am new to web programming. i am trying to connect database using jsp

  • 0

i am new to web programming. i am trying to connect database using jsp with odbc. i have already written a java code for this. now i need to run on Tomcat server. so i choose JSP to do this job.But this is showing me void type not allowed here and erors. how to run this code using jsp. what are my mistakes. please help me to solve in this.
now this is my code

 <%@page import="java.sql.*"%>
 <%@page import="java.util.*" %>
 <%@page import="java.util.logging.Level"%>
 <%@page import="java.util.logging.Logger"%>

 <%! 
 int i=0,j=0,k=0;
 Connection conn=null;
 Connection connection=null;
 static int count=0;

    String Cname[]=null;
    String Title[]=null;
    Statement stmt1=null;
    ResultSet NumOfRows=null;
    Statement stmt2=null;
    ResultSet SpreadsheetValues=null;
    Statement stmt3=null;
    ResultSet rs3=null;
    int RowCount;
         //this static function required to connect excel database
  static
  {
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    System.out.println("Exception in connecting to DB"+e.getMessage());
    }
  }

   // connect Sql database
    void ConnectSqlDB() {
  try{
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con = DriverManager.getConnection("jdbc:odbc:ServerDB","sa","sqladmin");
  System.out.println("MSSQL connected " +"<br>");
  }catch(Exception e){
  e.printStackTrace();
  System.out.println("Exception in connecting to DB"+e.getMessage());
  }
  }
  void ConnectExcelDB() throws SQLException{
     conn=DriverManager.getConnection("jdbc:odbc:spreadsheetdb","","");
 }
  void getRowcount() throws SQLException{
     stmt1=conn.createStatement();

     String Qs1="select count(*) from [Sheet1$]";
     NumOfRows=stmt1.executeQuery(Qs1);
     while(NumOfRows.next()){
     Rowcount=NumOfRows.getInt(1);
     }
     NumOfRows.close();
    }
     void getExcelValues() throws SQLException{
        stmt2=conn.createStatement();
        String Qs2="select * from [Sheet1$]";
        SpreadsheetValues=stmt2.executeQuery(Qs2);

        Cname=new String[Rowcount];
        Title=new String[Rowcount];
        while(SpreadsheetValues.next()){

    // Assigning Spread sheet values to String array

               Cname[j]=SpreadsheetValues.getString("Cname");
               Title[j]=SpreadsheetValues.getString("Title");
               j++;
         }
     }
          SpreadsheetValues.close();
          stmt2.close();
          conn.close();
          SpreadsheetValues=null;
          stmt2=null;
          conn=null;
 }
   %>
      <%=ConnectSqlDB()%>
      <%=ConnectExcelDB()%>
      <%=getRowcount()%>
      <%=getExcelValues()%>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:55:30+00:00Added an answer on May 27, 2026 at 7:55 pm

    Do not use <%= %> (Expression) to invoke void methods and you should have to avoid Java code in JSP (read SO thread).

    <%
      ConnectSqlDB();
      ConnectExcelDB();
      getRowcount();
      getExcelValues();
    %>
    
    <p>Total Records : <%=RowCount%>
    <p>Array element at 0 index <%=name[0]%>
    
    <%
     for(String v:name)
     {
       out.println("<br/>" + v);
     }
    %> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to web programming, I have mainly used java to create
I'm new to Java-based web programming and am trying to learn JSF from the
I'm new to web programming in general so this is probably a really simple
I am new to web programming...I have been asked to create a simple Internet
I'm relatively new to web application programming so I hope this question isn't too
I've came across this new acronym, SOFEA, apparently a new programming paradigm for web
I am relatively new to ASP.NET programming, and web programming in general. We have
i'm kinda new in web programming, i'm trying to design a search page. i
I am a college student slightly new to web programming and lately I have
I'm currently trying to install the new Microsoft WebMatrix Beta 2 (a web programming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.