Results 1 to 5 of 5
- 10-27-2010, 11:36 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 28
- Rep Power
- 0
URL problem in mysql connection in jsp
Hello All,
I am writing code for mysql connection using IP address with JSP. It is not connecting to mysql. can any one tell me solution for this:-(
Thanks in advance
Rashmi
below is the jsp file
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% Connection con = null;
ResultSet rs = null;
Statement st = null;
try {
String dbuser = "root";
String dbpass = "admin";
String url = "jdbc:mysql://192.168.0.13/mysql";
Class.forName("com.mysql.jdbc.Driver").newInstance ();
con = DriverManager.getConnection(url, dbuser, dbpass);
st = con.createStatement();
out.println("database connection esablished");
}
catch(SQLException e)
{
out.println("can not connect to database");
}
finally
{
}
%>
</body>
</html>
- 10-28-2010, 05:49 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 32
- Rep Power
- 0
paste error code
remove "out.println("can not connect to database");" line from the catch block and instead write: "out.print(e.getMessage());" ......run it and paste the error message. There may be a lot of reasons for not being able to connect to database..!!...Error message is important!
- 10-29-2010, 05:02 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 28
- Rep Power
- 0
Hello soumya,
Thanks for the quick reply,
the error message is like :
null, message from server: "Host '192.168.0.23' is not allowed to connect to this MySQL server"
Thanks in advance
Rashmi
- 10-30-2010, 03:22 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 32
- Rep Power
- 0
Expected solution
In your first post your url was ---
String url = "jdbc:mysql://192.168.0.13/mysql";--
But the error msg says: "192.168.0.23".... :confused:
whatever it is....it seems u don't have the permission for accessing or logging in from this machine(s) other than localhost.
Add 192.168.0.23(/13) as a user(or ask your db admin to do it), grant privileges, and hopefully it'll solve your problem!
I don't use mysql, but i think the command goes like this:
CREATE USER 'rashmi'@'192.168.0.23' IDENTIFIED BY 'yourPassword';
and then:
GRANT SELECT,INSERT,UPDATE,DELETE ON <database name>.* TO rashmi
in case you get stuck, you may refer to: MySQL :: MySQL 5.1 Reference Manual :: 5.5.2 Adding User Accounts
Hope this solves your problem...good luck!! :)
- 11-19-2010, 07:23 AM #5
Member
- Join Date
- Aug 2010
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
connection my mysql in jsp in myeclipse
By pranjul137 in forum New To JavaReplies: 8Last Post: 04-12-2010, 09:47 AM -
connection my mysql
By pranjul137 in forum New To JavaReplies: 5Last Post: 04-06-2010, 08:26 PM -
TWO IPs FOR MY MYSQL CONNECTION
By tugalsan in forum JDBCReplies: 2Last Post: 03-21-2010, 08:46 PM -
java mysql connection
By sysout in forum New To JavaReplies: 5Last Post: 10-31-2009, 10:48 AM -
no mysql connection
By scchia in forum New To JavaReplies: 12Last Post: 07-19-2008, 07:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks