User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 423,502 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,679 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1296 | Replies: 23 | Solved
Reply
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Can anyone please help me with connect to database

  #1  
May 26th, 2008
sorry for annoying, i am quite stupid in it.

<html>
<head>
<title>Welcome to the online Auction...</title></head>
<body>
 
 
<% try
 
{
 
	String strUsername = request.getParameter("username"); 
	String strPassword = request.getParameter("password"); 
	
	Class.forName ("mysql-connector-java-5.0.8-bin"); 
 
 	Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost/user.jsp,admin,admin");
 	
 	Statement myStatement = myConn.createStatement ();
 	
	String strSQL = "SELECT UserName,UserPwd from user where UserName="",UserPwd="";
	
 
	ResultSet myResult = myStatement.executeQuery(strSQL);
	
	String strUser = myResult.getString("UserName");
	String strPass = myResult.getString("Password");
	
	while(myResult.next())
    
    {
	
	if(strUsername.equals(strUser) && strPassword.equals(strPass))
	
                {
                    out.println("Login Successful!");
                }
                else
                {
                    out.println("Login Fail!");
                }
	
	}	
		
	myConn.close();
}
	catch(Exception e){} 
%>
			
</body> 
</html>
 

i am new to this.

Please help me with this.

my jar file name is mysql-connector-java-5.0.8-bin

Please help me out.

thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,432
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 11
Solved Threads: 295
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Can anyone please help me with connect to database

  #2  
May 26th, 2008
For once do not use JSP to connect to DB. JSP is for presentation and servlet is for logic. The order should be JSP collect data from user pass it on servlet. Servlet will validate data and if they correct it will attempt to connect to DB. If conection goes well DB operation is processed (insert/update/delete/chceck/retrieve) and servlet retrieve DB respond, after that servlet will either go to next page or return to previous

There is somewhere example how to do it that I posted about 2 years ago and it was recently re-open by somebody
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Re: Can anyone please help me with connect to database

  #3  
May 26th, 2008
can you show me some example for that...

i am too confuse with it

thanks
Reply With Quote  
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Re: Can anyone please help me with connect to database

  #4  
May 26th, 2008
i saw ur code for the connection
public class SomeClassName extends HttpServlet
{
Connection conn;
Statement stmt;
	
public void init() throws ServletException
{
	try
	{
		Class.forName("com.mysql.jdbc.Driver").newInstance();
	}
	catch (Exception ex)
	{
		System.out.println("Exception is : " + ex.toString() );
	}
}
	
public void doPost( HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
	try
	{
		conn = DriverManager.getConnection("jdbc:mysql://localhost/processing.jsp"
			+ "visualogic?UserName=admin&UserPwd=admin");
		stmt = conn.createStatement();
	}
	catch(SQLException ex)
	{
		System.out.println("SQLException : " + ex.getMessage() );
	}public class SomeClassName extends HttpServlet
{
Connection conn;
Statement stmt;
	
public void init() throws ServletException
{
	try
	{
		Class.forName("com.mysql.jdbc.Driver").newInstance();
	}
	catch (Exception ex)
	{
		System.out.println("Exception is : " + ex.toString() );
	}
}
	
public void doPost( HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
	try
	{
		conn = DriverManager.getConnection("jdbc:mysql://localhost/processing.jsp" 
			+ "visualogic?UserName=admin&UserPwd=admin");
		stmt = conn.createStatement();
	}
	catch(SQLException ex)
	{
		System.out.println("SQLException : " + ex.getMessage() );
	}

am i doing right?
what file shall i save to?
.jsp or.....
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,432
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 11
Solved Threads: 295
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Can anyone please help me with connect to database

  #5  
May 27th, 2008
Above example is servlet so it should ba save as java class
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Re: Can anyone please help me with connect to database

  #6  
May 28th, 2008
i get error for it
here is the error

org.apache.jasper.JasperException: /processing.jsp(1,17) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:200)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:150)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:162)
org.apache.jasper.compiler.ParserController.getPageEncodingForJspSyntax(ParserController.java:451)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:392)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:173)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:153)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,432
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 11
Solved Threads: 295
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Can anyone please help me with connect to database

  #7  
May 28th, 2008
Your connection string
Originally Posted by Visualogic View Post
conn = DriverManager.getConnection("jdbc:mysql://localhost/processing.jsp"
			+ "visualogic?UserName=admin&UserPwd=admin");		


VS


my connection string

Originally Posted by peter_budo View Post
conn = DriverManager.getConnection("jdbc:mysql://localhost/" 						+ "database_name?user=my_username&password=my_password");		

Can you explain me what is the purpose of processing.jsp in your code?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Re: Can anyone please help me with connect to database

  #8  
May 28th, 2008
it is trying to get to authencate the username and password.
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,432
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 11
Solved Threads: 295
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Can anyone please help me with connect to database

  #9  
May 28th, 2008
The "processing.jsp" is not supposed to be there. Connection string uses the database URL
jdbc:mysql://localhost/ , database name database_name , database user name UserName=admin and password UserPwd=admin to establish connection with database.

Please read through these Java tutorials, just be aware they using Derby database instead of MySQL
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Re: Can anyone please help me with connect to database

  #10  
May 28th, 2008
hmm, not really understand it

sorry for annoying
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 4:19 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC