Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot connect to mysql through netbeans

 
Alpesh Koli
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<%@page import="java.sql.DriverManager"%>
<%@page import="java.beans.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%
String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver).newInstance();

Connection con=null;
ResultSet rst=null;
Statement stmt=null;

try{
String url="jdbc:mysql://localhost/j1?username=<root> &password=<root> ";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage());
}
if(request.getParameter("action") != null){
String id=request.getParameter("id");
String data=request.getParameter("data");
stmt.executeUpdate("insert into emp(id,data) values('"+id+"','"+data+"')");
rst=stmt.executeQuery("select * from emp");
%>
<html>
<body>
<center>
<h2>Books List</h2>
<table border="1" cellspacing="0" cellpadding
="0">
<tr>
<td><b>S.No</b></td>
<td><b>Book Name</b></td>
<td><b>Author</.b></td>
</tr>
<%
int no=1;
while(rst.next()){
%>
<tr>
<td><%=no%></td>
<td><%=rst.getString("id")%></td>
<td> <%=rst.getString("data")
%> </td>
</tr>
<%
no++;
}
rst.close();
stmt.close();
con.close();
%>
</table>
</center>
</body>
</html>
<%}else{%>
<html>
<head>
<title>Book Entry FormDocument</title>
<script language="javascript">
function validate(objForm){
if(objForm.id.value.length==0){
alert("Please enter ID!");
objForm.bookname.focus();
return false;
}
if(objForm.data.value.length==0){
alert("Please enter DATA!");
objForm.author.focus();
return false;
}
return true;
}
</script>
</head>

<body>
<center>
<form action="BookEntryForm.jsp" method="post"
name="entry" onSubmit="return
validate(this)">
<input type="hidden" value="list" name="action">
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<table>
<tr>
<td colspan="2" align="center">
<h2>Book Entry Form</h2></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>Book Name:</td>
<td><input name="bookname" type=
"text" size="50"></td>
</tr>
<tr>
<td>Author:</td><td><input name=
"author" type="text" size="50"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<% } %>
 
sailaja usha
Greenhorn
Posts: 13
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the error?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic