473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Global MySQL Con String for JSP files

ak1dnar
1,584 Expert 1GB
I need to put the connection string in a global file.because again and again i cant edit the lines. if there is Global file how can call for it.in php i can use [PHP]require 'dbconfle.php' ;[/PHP]

Like wise what is for JSP.

Then only thing i have to do just change a single file.Any Ideas? Here is the Current code.

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.sql.*" %>
  2. <%
  3.         String driver = "org.gjt.mm.mysql.Driver";
  4.         Class.forName(driver).newInstance();
  5.  
  6.  
  7.         Connection con=null;
  8.         ResultSet rst=null;
  9.  
  10.         Statement stmt=null;
  11.  
  12.     try
  13.     {
  14.         String url="jdbc:mysql://localhost/books?user=root&password=dba";
  15.         con=DriverManager.getConnection(url);
  16.         stmt=con.createStatement();
  17.     }
  18.     catch(Exception e)
  19.     {
  20.             System.out.println(e.getMessage());
  21.     }
  22.  
  23.     if(request.getParameter("action") != null)
  24.     {  
  25.  
  26.       String bookname=request.getParameter("bookname");
  27.       String author=request.getParameter("author");
  28.  
  29.       stmt.executeUpdate("insert into books_details(book_name,author) values('"+bookname+"','"+author+"')");
  30.  
  31.  
  32.       rst=stmt.executeQuery("select * from books_details");
  33.  
  34.       %>
  35.  
  36.  
  37.  
  38. <html>
  39.    <body>
  40.    <center><h2>Books List</h2>
  41.    <table border="1" cellspacing="0" cellpadding="0">
  42.  
  43.       <tr><td><b>S.No</b></td><td><b>Book Name</b></td><td><b>Author</.b></td></tr>
  44.       <%
  45.           int no=1;
  46.  
  47.             while(rst.next()){
  48.  
  49.       %>
  50.  
  51.             <tr><td><%=no%></td><td><%=rst.getString("book_name")%></td><td><%=rst.getString("author")%></td></tr>
  52.  
  53.       <%    
  54.             no++;
  55.             }
  56.  
  57.              rst.close();
  58.              stmt.close();
  59.              con.close();
  60.  
  61.  
  62.  
  63.         %>
  64.         <tr>
  65.    </table>
  66.    </center>
  67.    <body>
  68. <html>
  69. <%}else{%>
  70.  
  71. <html>
  72.         <head>
  73.         <title>Book Entry FormDocument</title>
  74.  
  75.          <script language="javascript">
  76.             function validate(objForm){
  77.  
  78.                 if(objForm.bookname.value.length==0){
  79.                     alert("Please enter  Book Name!");
  80.                     objForm.bookname.focus();
  81.                     return false;
  82.                 }
  83.  
  84.                 if(objForm.author.value.length==0){
  85.                     alert("Please enter Author name!");
  86.                     objForm.author.focus();
  87.                     return false;
  88.                 }
  89.  
  90.                 return true;
  91.             }
  92.           </script>
  93.  
  94.         </head>
  95.         <body><center>
  96.         <form action="BookEntryForm.jsp" method="post" name="entry" onSubmit="return validate(this)">
  97.         <input type="hidden" value="list" name="action">
  98.         <table border="1" cellpadding="0" cellspacing="0">
  99.             <tr>
  100.                 <td>
  101.                     <table>
  102.                         <tr><td colspan="2" align="center"><h2>Book Entry Form</h2></td></tr>
  103.                         <tr><td colspan="2">&nbsp;</td></tr>
  104.                         <tr><td>Book Name:</td><td><input name="bookname" type="text" size="50"></td></tr>
  105.                         <tr><td>Author:</td><td><input name="author" type="text" size="50"></td></tr>
  106.                         <tr><td colspan="2" align="center"><input type="submit" value="Submit"></td></tr>
  107.                     </table>
  108.                 </td>
  109.             </tr>
  110.         </table>
  111.         </form>
  112.         </center>
  113.  
  114.         </body>
  115.   </html>
  116.  
  117.  
  118.  
  119. <%}%>
  120.  
  121.  
  122.  
Mar 28 '07 #1
2 2203
r035198x
13,262 8TB
I need to put the connection string in a global file.because again and again i cant edit the lines. if there is Global file how can call for it.in php i can use [PHP]require 'dbconfle.php' ;[/PHP]

Like wise what is for JSP.

Then only thing i have to do just change a single file.Any Ideas? Here is the Current code.

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.sql.*" %>
  2. <%
  3.         String driver = "org.gjt.mm.mysql.Driver";
  4.         Class.forName(driver).newInstance();
  5.  
  6.  
  7.         Connection con=null;
  8.         ResultSet rst=null;
  9.  
  10.         Statement stmt=null;
  11.  
  12.     try
  13.     {
  14.         String url="jdbc:mysql://localhost/books?user=root&password=dba";
  15.         con=DriverManager.getConnection(url);
  16.         stmt=con.createStatement();
  17.     }
  18.     catch(Exception e)
  19.     {
  20.             System.out.println(e.getMessage());
  21.     }
  22.  
  23.     if(request.getParameter("action") != null)
  24.     {  
  25.  
  26.       String bookname=request.getParameter("bookname");
  27.       String author=request.getParameter("author");
  28.  
  29.       stmt.executeUpdate("insert into books_details(book_name,author) values('"+bookname+"','"+author+"')");
  30.  
  31.  
  32.       rst=stmt.executeQuery("select * from books_details");
  33.  
  34.       %>
  35.  
  36.  
  37.  
  38. <html>
  39.    <body>
  40.    <center><h2>Books List</h2>
  41.    <table border="1" cellspacing="0" cellpadding="0">
  42.  
  43.       <tr><td><b>S.No</b></td><td><b>Book Name</b></td><td><b>Author</.b></td></tr>
  44.       <%
  45.           int no=1;
  46.  
  47.             while(rst.next()){
  48.  
  49.       %>
  50.  
  51.             <tr><td><%=no%></td><td><%=rst.getString("book_name")%></td><td><%=rst.getString("author")%></td></tr>
  52.  
  53.       <%    
  54.             no++;
  55.             }
  56.  
  57.              rst.close();
  58.              stmt.close();
  59.              con.close();
  60.  
  61.  
  62.  
  63.         %>
  64.         <tr>
  65.    </table>
  66.    </center>
  67.    <body>
  68. <html>
  69. <%}else{%>
  70.  
  71. <html>
  72.         <head>
  73.         <title>Book Entry FormDocument</title>
  74.  
  75.          <script language="javascript">
  76.             function validate(objForm){
  77.  
  78.                 if(objForm.bookname.value.length==0){
  79.                     alert("Please enter  Book Name!");
  80.                     objForm.bookname.focus();
  81.                     return false;
  82.                 }
  83.  
  84.                 if(objForm.author.value.length==0){
  85.                     alert("Please enter Author name!");
  86.                     objForm.author.focus();
  87.                     return false;
  88.                 }
  89.  
  90.                 return true;
  91.             }
  92.           </script>
  93.  
  94.         </head>
  95.         <body><center>
  96.         <form action="BookEntryForm.jsp" method="post" name="entry" onSubmit="return validate(this)">
  97.         <input type="hidden" value="list" name="action">
  98.         <table border="1" cellpadding="0" cellspacing="0">
  99.             <tr>
  100.                 <td>
  101.                     <table>
  102.                         <tr><td colspan="2" align="center"><h2>Book Entry Form</h2></td></tr>
  103.                         <tr><td colspan="2">&nbsp;</td></tr>
  104.                         <tr><td>Book Name:</td><td><input name="bookname" type="text" size="50"></td></tr>
  105.                         <tr><td>Author:</td><td><input name="author" type="text" size="50"></td></tr>
  106.                         <tr><td colspan="2" align="center"><input type="submit" value="Submit"></td></tr>
  107.                     </table>
  108.                 </td>
  109.             </tr>
  110.         </table>
  111.         </form>
  112.         </center>
  113.  
  114.         </body>
  115.   </html>
  116.  
  117.  
  118.  
  119. <%}%>
  120.  
  121.  
  122.  
You can store the String as an Attribute or in the session
Mar 28 '07 #2
ak1dnar
1,584 Expert 1GB
If its only way to do it I'll give it a try.Thanks.
Can i make this by using a bean class.
Mar 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
4
by: Ian Davies | last post by:
Hello all The following code allows me to connect to a local MySQL database on my pc from a VB6 project. **************************************************************************** ** Dim...
9
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
1
by: Jarle Aase | last post by:
Hi, I wrote a multilanguage cms system a few years ago. Different languages are handled by loading php-files where each language-specific string is assigned to a normal php-variable ($LNG...
2
by: arun1985 | last post by:
In the project i am using i am having the following code and when i upload it to the server.Its givig me the following error in the global.cs file. Server Error in '/' Application. ...
8
by: The Natural Philosopher | last post by:
This is so weird. What I am trying to do is to upload files and stuff them in a mysql database. Everything works except the file content is zero. using the load_file command from mysql...
5
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql server with java application but when i try to compile,the compilation is successful and during execution i get the following message, ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.