thanx to all of u friends. mt problem was solved by putting connector :mysql-connector-java-3.0.16-ga-bin.jar in jdk ----jre folder in lib----ext and also copy it in tomcat---lib.
muskan -1 Newbie Poster
oh my dear ! i am working with tomacat apache 5.0.28 but in order to work with beans there is also need to make a java file and place it in classes in tomcat directory .thats why i am running the program on jdk 1.5 +kawapro5 in order to connect the mysql database with jsp.
and the the jsp code is given below that i am using with this java file or class file
<%@page import="java.sql.*,java.util.*" %>
<jsp:useBean id="connBean" scope="page" class="ConnBean" />
<html>
<head>
<script>
function validate(f){
if(f.id.value.length == 0){
alert('User Id can no be empty.');
f.id.focus();
return false;
}
else if(f.pswd.value.length == 0){
alert('Password can no be empty.');
f.pswd.focus();
return false;
}
}
</script>
<title>Log In</title>
</head>
<body onLoad="document.login.id.focus()">
<center>
<%
String query="insert into dbname(id,password) values('2222','222')";
String url=request.getRemoteAddr();
try
{
int t=connBean.executeUp(query);
if(t>0)
out.print("query successfull");
else
out.print("query not successfull");
}
catch(Exception e)
{}
</body>
</html>
but how tomcat will run it properly untill its class file(.java file) works properly.
muskan -1 Newbie Poster
Bad, bad, bad. Never copy anything to the lib/ext directory of the jre. Learn how to use and set classpaths properly. If he has the proper jarfile, and places it in the WEB-INF/lib directory of the web application he is trying to reach, the classes will be found. If they are not, he has done something wrong. Either copied it to the lib directory of the wrong application, not copied the right jarfile, or, maybe, somehow or another, changed the tomcat configuration so that it does not look there. Sorry to say it, but all of those things are "his problem", and copying anything to the lib/ext directory is not the answer, regardless of whether or not "it works".
1) i have copied mysql-connector-java-3.0.8-stable-bin this zipped file and also imn unzipped form in WEBINF/lib .which jar files u are talking about please mention complete name .and
2) tell me by doing this can i remove the error encountering in kawapro also as i have mentioned above .
muskan -1 Newbie Poster
please tell me how to put the mysql driver in the class path please mention the method kindly.thanks
muskan -1 Newbie Poster
please help me to resolve the databasbase connectivity problem in java for mysql .i am using jdk 1.5 ,if there is need to put a file then please mention where it should be copied ,and i am writing the code and error occuring that code.
code:
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.*;
import java.io.*;
public class ConnBean
{
Connection conn;
Statement st ;
public ConnBean()
{
String sqlDriver= "com.mysql.jdbc.Driver";
String hostName = "localhost:3306/";
String dbName = "mydb";
String userID = "root";
String password = "webportal";
//databse URL
String dbURL = "jdbc:mysql://" + hostName + dbName;
try {
Class.forName(sqlDriver);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(dbURL, userID, password);
st = conn.createStatement();
System.out.println("db connected");
}
catch (SQLException e) {
System.out.println("Exception occured during get connection" + e);
}
}
public static void main(String asdas[]) throws SQLException
{
ConnBean conn=new ConnBean();
//ResultSet rs=conn.executeQ("select * from clients");
}
}
Error
D:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - C:\final project\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;d:\program files\java\jdk1.5.0\lib\tools.jar;d:\program files\java\jdk1.5.0\jre\lib\rt.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at ConnBean.<init>(ConnBean.java:25)
at ConnBean.main(ConnBean.java:44)
Exception occured during get connectionjava.sql.SQLException: No suitable driver
Process Exit...
peter_budo commented: Multiposting is not welcome here -1
muskan -1 Newbie Poster
Is there any need to copy the .jar files(that are mysql-connector-java-3.0.8-stable-bin) in jdk.If so then where these files should be copied in order to include in the class path of java.please answer it to solve my problme.thanx
muskan -1 Newbie Poster
Copy that jar file into WEB-INF/lib, not into just any generic tomcat lib directory.
yes i have copied the .jar files in WEB-INF/lib but still when i have compiled database connectivity program with mysql in java it gave the same error.
D:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - C:\final project\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;d:\program files\java\jdk1.5.0\lib\tools.jar;d:\program files\java\jdk1.5.0\jre\lib\rt.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at ConnBean.<init>(ConnBean.java:25)
at ConnBean.main(ConnBean.java:44)
Exception occured during get connectionjava.sql.SQLException: No suitable driver
Process Exit...
muskan -1 Newbie Poster
yes i have installed javabut and it is working properly .now wat can b done. please help me to solve this problem
muskan -1 Newbie Poster
please tell me which .jar file has to saved and where in jdk or in tomcat althought i have mysql-connector-java-3.0.8-stable-bin.jar file that i have copied in tomcat in libs .please tel are u talking about this .jar file now wat i have to do?please guide me kindly
muskan -1 Newbie Poster
i am using Apache Tomcat Version 5.0.28 but it is not working well i have just typed a simple code and it is giving error .i am providing error and also code please giude me where is the problem , i am new to jsp please help me thanx.
.jsp file contains following code:
/code
<%@ page language="java" %>
<% String s1="",s2="";
s1=request.getParameter("T1");
s2=request.getParameter("T2");
%>
<%= s1 %>
<%= s2 %>
/code
and .html file contains
/code
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td width="50%">
<form method="POST" action="ja.jsp">
<!--webbot bot="SaveResults" U-File="file:///D:/Documents and Settings/WAQAR/My Documents/My Webs/_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><p> </p>
<p>username</p>
<p> </td>
<td width="50%"><input type="text" name="T1" size="20"></td>
</tr>
<tr>
<td width="50%">password</td>
<td width="50%"><input type="password" name="T2" size="20"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</body>
</form>
</html>
/code
and the following error is displayed by tomcat when i used to run it plz help me.
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:346)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
Unable to find …
muskan -1 Newbie Poster
i am writing code and also the error i am facing in database connectivity in jsp to mysql .plz help me .thanx
code
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.*;
import java.io.*;
public class ConnBean
{
Connection conn;
Statement st ;
public ConnBean()
{
String sqlDriver= "com.mysql.jdbc.Driver";
String hostName = "localhost:3306/";
String dbName = "mydb";
String userID = "root";
String password = "webportal";
//databse URL
String dbURL = "jdbc:mysql://" + hostName + dbName;
try {
Class.forName(sqlDriver);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(dbURL, userID, password);
st = conn.createStatement();
System.out.println("db connected");
}
catch (SQLException e) {
System.out.println("Exception occured during get connection" + e);
}
}
public static void main(String asdas[]) throws SQLException
{
ConnBean conn=new ConnBean();
//ResultSet rs=conn.executeQ("select * from clients");
}
}
and the error that jdk 1.5 ( with mysql 5.0.41) is showing is
C:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - D:\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;c:\program files\java\jdk1.5.0\lib\tools.jar;c:\program files\java\jdk1.5.0\jre\lib\rt.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at ConnBean.<init>(ConnBean.java:25)
at ConnBean.main(ConnBean.java:44)
Exception occured during get connectionjava.sql.SQLException: No suitable driver
Process Exit...