On Tuesday 29 May 2007 01:14, Teh Noranis Mohd Aris wrote: > Thank you so much for the reply. I've put "jdbc:mysql://localhost:8080/teh > but I got the error java.lang.ClassNotFoundException: > com.mysql.jdbc.Driver. I'm very new to using mysql database and servlet. > Can you please explain to me how to create the database name and its > fields? Should I install any driver? How can it be done? Please help. Thank > you. > > Yours Sincerely, > TEH > > Foo Shyn <[EMAIL PROTECTED]> wrote: > Hi, > > yyyy would be ur database port, xxx will be ur database name > > HTH > FooShyn > > Teh Noranis Mohd Aris wrote: > > Hi, > > > > I would like to access mysql database from a servlet but I'm not sure > > what to initialize for the String connectionURL marked as > > "jdbc:mysql://localhost:yyyy/xxx" in the program below. I got this > > program from the internet which I would like to run in my computer. Can > > anyone please explain to me what the parameters "yyyy" and "xxx" should > > be? > > > > Yours Sincerely, > > TEH > > > > Following is part of the program: > > ....... > > public void doPost(HttpServletRequest request, HttpServletResponse > > response) throws ServletException, IOException{ > > response.setContentType("text/html"); > > PrintWriter pw = response.getWriter(); > > String connectionURL = "jdbc:mysql://localhost:yyyy/xxx"; > > Connection connection=null; > > try{ > > String username = request.getParameter("username"); > > String password = request.getParameter("password"); > > pw.println(username); > > pw.println(password); > > Class.forName("com.mysql.jdbc.Driver").newInstance(); > > connection = DriverManager.getConnection(connectionURL, "root", "root"); > > PreparedStatement pst = connection.prepareStatement > > ("insert into login_table values(?,?)"); > > ....... > > > > > > --------------------------------- > > Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's > > on, when. > > > > ------------------------------------------------------------------------ > > > > No virus found in this incoming message. > > Checked by AVG Free Edition. > > Version: 7.5.472 / Virus Database: 269.8.0/821 - Release Date: 5/27/2007 > > 3:05 PM > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------- > Shape Yahoo! in your own image. Join our Network Research Panel today!
There are many great tutorials on the web on how to do this, here is a url with the basic servlet code: http://www.cs.unc.edu/Courses/comp118/docs/lessons/java/java_jdbc/jdbcServletMysql.html That page however doesn't tell you that you need to place the mysql driver(which should be a jar file) in your web application's WEB-INF/lib folder. Good Luck, Zack --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]