473,772 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with JDBC and MySQL

5 New Member
Hello partners.

I have an issue using jdbc and a DB in MySQL.
The problem is that I want to make a seach using the Last Name of a person stored in a MySQL DB, from a JSP
The problem is that I cannot determine which sentence to use for this purpose, that can help me to display the information of the person who match with the search criteria.

This is my actual Servlet.

Expand|Select|Wrap|Line Numbers
  1. import java.io.IOException;
  2. import java.io.PrintWriter;
  3. import java.sql.*;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6. import java.net.*;
  7.  
  8. public class Changer extends HttpServlet {
  9.  
  10.     public Changer() {
  11.         super();
  12.     }
  13.  
  14.     public void doGet(HttpServletRequest request, HttpServletResponse response)
  15.             throws ServletException, IOException {
  16.  
  17.         response.setContentType("text/html");
  18.         PrintWriter out = response.getWriter();
  19.  
  20.         String name=request.getParameter("name");
  21.         String last=request.getParameter("last");
  22.         String country=request.getParameter("country");
  23.         String profile=request.getParameter("profile");
  24.         String company=request.getParameter("company");
  25.         String platform=request.getParameter("platform");
  26.         String URL="jdbc:mysql://localhost:3806/Base01";
  27.  
  28.         try
  29.                 {
  30.                     Class.forName("com.mysql.jdbc.Driver");
  31.                 }catch(Exception ex)
  32.                 {
  33.                     out.println("error!");
  34.                 }
  35.  
  36.                 try
  37.                 {
  38.                     Connection con=DriverManager.getConnection(URL,"superou","kliojk126");
  39.                     Statement stmt=con.createStatement();
  40.                     ResultSet rst=null;
  41.  
  42.  
  43.                     try{
  44.                     String SQL= "SELECT * FROM 01thllo1 WHERE lastN =
  45.                     System.out.print(SQL);
  46.                     rst=stmt.executeQuery(SQL);    
  47.  
  48.                     out.println("<TABLE BORDER CELLSPACING=3 CELLPADDING=3>");
  49.  
  50.                     while(rst.next()){
  51.                     out.println("<tr>");
  52.                     out.println("<td>"+rst.getString("name"));
  53.                     out.println("<td>"+rst.getString("last"));
  54.                     out.println("<td>"+rst.getString("country"));
  55.                     out.println("<td>"+rst.getString("profile"));
  56.                     out.println("<td>"+rst.getString("company"));
  57.                     out.println("<td>"+rst.getString("platform"));
  58.                                         }//while
  59.  
  60.                     }catch(SQLException seq)
  61.  
  62.                     {
  63.                         System.err.println("SQLException " + seq.getMessage());
  64.                     }
  65.  
  66.  
  67.         }catch(SQLException se){
  68.         System.err.println("SQLException: " + se.getMessage());
  69.                     }
  70.         out.println("</TABLE>");
  71.     }
  72.  
  73. }
  74.  
  75.  
So I will appreciate a lot if you can help me to make a correcr SELECT statement, because I`ve tried a lot of them and no one gives me the result that I want.

Thank you very much for your attention and help.
Jul 18 '07 #1
6 1629
madhoriya22
252 Contributor
What do you mean by sentence here - "The problem is that I cannot determine which sentence to use for this purpose, that can help me to display the information of the person who match with the search criteria."
Jul 19 '07 #2
mwasif
802 Recognized Expert Contributor
If you are looking for how to search in mysql then use this query

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table_name WHERE name='name to search'
Or you can use FULLTEXT search
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table_name WHERE MATCH(name_column) AGAINST('name to search')
.

But I still not clear what do you want!
Jul 19 '07 #3
IvanJ2EE
5 New Member
Ok let me explain myself better.

In a JSP called Changes.jsp, I show a page where the user should introduce the last name of the person to search in the database the full information of that person (name, country, etc.)

When the user click Search button, the Servlet should look in the database and get the full info of the person, and display in in the page.

So the problem is that I cannot find a SQL expression that help me to find the information of the Person based in the Parameter that the user puts on the Search TextField.

I hope this explains my problem better...
Thank you all for your help.
Jul 19 '07 #4
mwasif
802 Recognized Expert Contributor
In my previous reply, I have mentioned the query to search the respective result.
Jul 19 '07 #5
ak1dnar
1,584 Recognized Expert Top Contributor
Hi are you looking for something like this?

Expand|Select|Wrap|Line Numbers
  1. String SQL= "SELECT * FROM 01thllo1 WHERE column_name like '%"+pass_search_string_variable_here+"%'";
  2.  
Edit: Make sure to print it as a single line...
Jul 19 '07 #6
IvanJ2EE
5 New Member
Ouch...I just found the mistake..
The problem is that I was calling the wrong parameter, so when I called it from the Jsp the servlet never found the parameter...
Thank you all for your replies and your time...

God Bless u.
Jul 19 '07 #7

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

Similar topics

0
2269
by: Nils Valentin | last post by:
Hi MySQL Fans ;-), Is it possible that the 3.08 series allows to connect to 4.0.14 versions but not to the 4.1 alpha-versions ? I get belows error when tryig to connect from DbVisualizer which was working fine until a while ago. I haven't watched it recently, and haven't changed anything I am aware off right now. After I realized the problem I tried many 3.08 versions with the same symptom. Watch were it says "Unknown system variable...
0
512
by: Ma Mei | last post by:
Dear administrator, Now I have a quesion and want to get your help. When I insert an image file data (data size > 64KB) to a BLOB field of MySQL database by com.mysql.jdbc.driber,there is error. Error message as follows: "aq.executeQuery:Communication link failure:comm.mysql.jdbc.packetTooBigException" The part of my program as follows: ............... FileInputStream fis = new FileInputStream("untitl2.gif");
0
4245
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version of MySQL 5.0? When trying to connect I am getting: ** BEGIN NESTED EXCEPTION **
0
1228
by: yksoni | last post by:
we are working in IBM aglets 2.0.2 with mysql 4.0.2. When we try to access database through tahiti server i.e.aglets we get following error. java.net.SocketException MESSAGE: java.security.AccessControlException: access denied (java.net.SocketPer mission 127.0.0.1:3306 connect,resolve) STACKTRACE: java.net.SocketException: java.security.AccessControlException: access denied (j
5
2043
oll3i
by: oll3i | last post by:
my librarybean package library.ejb; import java.sql.*; import javax.ejb.*; import library.common.*; @Stateless @Remote
2
2621
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in another screen. All of this has to be done with java servlets. I think there's something I don't see and it's wrong. My problem is that anything I enter in the search bar appears as a result in the results page, even if there's not such a name in...
0
6519
by: neuraljay | last post by:
hi everyone. I am trying to build a jsp using webwork, hibernate and mysql. And right now I am doing its unit testing. Everytime I run the test I am getting this error: Error JDBC exception on Hibernate data access; nested exception is org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access; nested exception is...
0
1475
by: yoach | last post by:
i dont the prpopties file withe db2 is this ok:? # The target database platform. torque.database = db2 # The target package to put the generated classes in. torque.targetPackage = com.kazmier.om # The JDBC URL that Torque can use to create and # drop databases if instructed to do so.
1
1435
by: samathak | last post by:
Hi, I have implemented com.mysql.jdbc.ConnectionPropertiesTransform class. In the jdbc connection url, I have added propertiesTransform=com.mysql.jdbc.ConnectionPropertiesTransformImpl attribute.
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.