Trouble connecting to MySQL database with Hibernate

I'm using red hat studio pro. I created an hibernate.cfg.xml file with
the hibernate tools.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
     <property name="hibernate.connection.driver_jar">mysql-connector-
java-5.0.6-bin.jar</property>
<property
name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</
property>
<property name="hibernate.connection.password"> </property>
<property name="hibernate.connection.url">jdbc:mysql://
localhost/eshop</property>
<property name="hibernate.connection.username">user</property>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</
property>
</session-factory>
</hibernate-configuration>
Reverse Engineering was no problem, it found the database, could read
the tables and create the java classes.
Now I tried to open a simple connection to the database and that
doesn*t work. I always get a "no suitable driver found" error.
Code:
     Configuration config = new Configuration()
     .setProperty("hibernate.dialect",
"org.hibernate.dialect.MySQLInnoDBDialect")
     .setProperty("hibernate.connection.driver_class",
"org.gjt.mm.mysql.Driver")
     .setProperty("hibernate.connection.driver_jar", "mysql-connector-
java-5.0.6-bin.jar")
     .setProperty("hibernate.connection.password", " ")
     .setProperty("hibernate.connection.url", "jdbc:mysql://localhost:
3306/eshop")
     .setProperty("hibernate.connection.username", "user")
     .addClass(Adressen.class);
     config.configure();
     SessionFactory sessionFactory = config.buildSessionFactory();
     Session session = sessionFactory.openSession();
     Transaction tx = null;
     try {
          tx = session.beginTransaction();
          System.out.println("works");
     } catch (Exception e) {
          if (tx != null) {
               tx.rollback();
               System.out.println("error - rollback");
     } finally {
          session.close();
     sessionFactory.close();
The errors I'm getting are:
Code:
23:41:05,187 INFO [Environment] Hibernate 3.2.4.sp1
23:41:05,187 INFO [Environment] loaded properties from resource
hibernate.properties: {hibernate.co
nnection.username=user, hibernate.connection.password=****,
hibernate.dialect=org.hibernate.dialect.
MySQLInnoDBDialect, hibernate.connection.url=jdbc:mysql://localhost:
3306/eshop, hibernate.bytecode.u
se_reflection_optimizer=false,
hibernate.connection.driver_class=com.mysql.jdbc.Driver}
23:41:05,187 INFO [Environment] Bytecode provider name : javassist
23:41:05,203 INFO [Environment] using JDK 1.4 java.sql.Timestamp
handling
23:41:05,312 INFO [Configuration] Reading mappings from resource:
hibernateGenerated/Adressen.hbm.x
ml
23:41:05,312 INFO [Configuration] Reading mappings from resource:
hibernateGenerated/Adressen.hbm.x
ml
23:41:05,515 INFO [HbmBinder] Mapping class:
hibernateGenerated.Adressen -> Adressen
23:41:05,531 INFO [Configuration] configuring from resource: /
hibernate.cfg.xml
23:41:05,531 INFO [Configuration] Configuration resource: /
hibernate.cfg.xml
23:41:05,546 INFO [Configuration] Configured SessionFactory: null
23:41:05,656 INFO [DriverManagerConnectionProvider] Using Hibernate
built-in connection pool (not f
or production use!)
23:41:05,656 INFO [DriverManagerConnectionProvider] Hibernate
connection pool size: 20
23:41:05,656 INFO [DriverManagerConnectionProvider] autocommit mode:
false
23:41:05,656 INFO [DriverManagerConnectionProvider] using driver:
org.gjt.mm.mysql.Driver at URL: j
dbc:mysql://localhost/eshop
23:41:05,656 INFO [DriverManagerConnectionProvider] connection
properties: {driver_jar=mysql-connec
tor-java-5.0.6-bin.jar, user=user, password= }
23:41:05,656 WARN [SettingsFactory] Could not obtain connection
metadata
java.sql.SQLException: No suitable driver found for jdbc:mysql://
localhost/eshop
     at java.sql.DriverManager.getConnection(Unknown Source)
     at java.sql.DriverManager.getConnection(Unknown Source)
     at
org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionPr
ovider.java:110)
     at
org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
84)
     at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:
2009)
     at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:
1292)
     at sample.RegisterAciton.writeInDatabase(RegisterAciton.java:147)
     at sample.RegisterAciton.execute(RegisterAciton.java:246)
     at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:
484)
     at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:
274)
     at org.apache.struts.action.ActionServlet.process(ActionServlet.java:
1482)
     at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:
525)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
     at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290
     at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
     at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:
96)
     at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
235
     at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
     at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
230)
     at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
175)
     at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:
179)
     at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:
84)
     at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
     at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
104)
     at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:
157)
     at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
     at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
241)
     at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844)
     at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:580)
     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
447)
     at java.lang.Thread.run(Unknown Source)
23:41:06,046 INFO [Dialect] Using dialect:
org.hibernate.dialect.MySQLInnoDBDialect
23:41:06,046 INFO [TransactionFactoryFactory] Using default
transaction strategy (direct JDBC trans
actions)
23:41:06,046 INFO [TransactionManagerLookupFactory] No
TransactionManagerLookup configured (in JTA
environment, use of read-write or transactional second-level cache is
not recommended)
23:41:06,046 INFO [SettingsFactory] Automatic flush during
beforeCompletion(): disabled
23:41:06,046 INFO [SettingsFactory] Automatic session close at end of
transaction: disabled
23:41:06,046 INFO [SettingsFactory] Scrollable result sets: disabled
23:41:06,062 INFO [SettingsFactory] JDBC3 getGeneratedKeys():
disabled
23:41:06,062 INFO [SettingsFactory] Connection release mode: auto
23:41:06,062 INFO [SettingsFactory] Maximum outer join fetch depth: 2
23:41:06,062 INFO [SettingsFactory] Default batch fetch size: 1
23:41:06,062 INFO [SettingsFactory] Generate SQL with comments:
disabled
23:41:06,062 INFO [SettingsFactory] Order SQL updates by primary key:
disabled
23:41:06,062 INFO [SettingsFactory] Order SQL inserts for batching:
disabled
23:41:06,062 INFO [SettingsFactory] Query translator:
org.hibernate.hql.ast.ASTQueryTranslatorFacto
ry
23:41:06,062 INFO [ASTQueryTranslatorFactory] Using
ASTQueryTranslatorFactory
23:41:06,062 INFO [SettingsFactory] Query language substitutions: {}
23:41:06,062 INFO [SettingsFactory] JPA-QL strict compliance:
disabled
23:41:06,062 INFO [SettingsFactory] Second-level cache: enabled
23:41:06,062 INFO [SettingsFactory] Query cache: disabled
23:41:06,062 INFO [SettingsFactory] Cache provider:
org.hibernate.cache.NoCacheProvider
23:41:06,062 INFO [SettingsFactory] Optimize cache for minimal puts:
disabled
23:41:06,062 INFO [SettingsFactory] Structured second-level cache
entries: disabled
23:41:06,078 INFO [SettingsFactory] Statistics: disabled
23:41:06,078 INFO [SettingsFactory] Deleted entity synthetic
identifier rollback: disabled
23:41:06,078 INFO [SettingsFactory] Default entity-mode: pojo
23:41:06,078 INFO [SettingsFactory] Named query checking : enabled
23:41:06,125 INFO [SessionFactoryImpl] building session factory
23:41:06,437 INFO [SessionFactoryObjectFactory] Not binding factory
to JNDI, no JNDI name configure
d
23:41:06,515 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState:
08001
23:41:06,515 ERROR [JDBCExceptionReporter] No suitable driver found
for jdbc:mysql://localhost/eshop
23:41:06,515 INFO [SessionFactoryImpl] closing
23:41:06,515 INFO [DriverManagerConnectionProvider] cleaning up
connection pool: jdbc:mysql://local
host/eshop
Can anybody tell me, what I'm doing wrong?

ClassNotFoundException means the driver isn't loaded. "No suitable driver" usually tells me that the syntax in the connection URL is incorrect for some reason.
Make sure you have an up to date driver JAR:
http://www.mysql.com/products/connector/j/
The driver class name should be com.mysql.jdbc.Driver
%

Similar Messages

  • Trouble connecting to mySql database

    Hi Forum
    I have a site hosted with Godaddy, and have created a database, but I can not connect to the database with DW.
    1)  I made made sure that the invisible file _mmServerScripts folder and the Connections folder are present both on my local machine in the root directory and on the server.
    2) I can connect to the hosting account with FTP.
    3) I can connect to the database via Goddaddy and PHPadmin.
    3) I have pointed the test server to the same url as the hosting account but to a folder in the directory that is called test_server.
    (I have used this approach before, and it worked then)
    4) I have tried to log on with the URL that PHP admin tells me: http://nbst.db.6113589.hostedresource.com/ and also with http://173.201.136.50
    5) I am getting the standard error code 404 suggesting:
    "a) There is no testing server running on the server machine
    b) The testing server specifed for this site does not map to http://173.201.144.128/_mmServerScripts/MMHTTPDB.php Url. Verify that the URL Prefix maps to the root of the site. "
    6) The error message refers to 173.201.144.128. This is an unknown IP to me. The database is supposed to be at  173.201.136.50
    What am I doing wrong??
    ggaarde

    ClassNotFoundException means the driver isn't loaded. "No suitable driver" usually tells me that the syntax in the connection URL is incorrect for some reason.
    Make sure you have an up to date driver JAR:
    http://www.mysql.com/products/connector/j/
    The driver class name should be com.mysql.jdbc.Driver
    %

  • Connecting to MySQL Database with Servlet

    Hi All,
    I want to connect to MySQL Database from servlet.
    I am using Tomcat websever 3.3.1, where i have to set classpath of mysql jdbc driver.
    I tried by copying mysql jdbc driver in so many directiories of Tomcat server but it is
    giving me error like "no specified driver find"
    So please send me all the solutions and how to set the classpath to connect to
    mysql database.
    Thanks

    U r correct that so many people are giving me solutions but that are not working for me
    I think i not correct in setting the classapath to mysql jdbc driver.
    1)I have unjarred correctly and all the classes are present in that.
    yes driver class is there in that .
    2)Now i am using new version of the mysqljdbc that is 2.0.13
    If now any driver after this send me url i will download it and use it
    3)I am unable to under stand what is yourcontext in
    yourcontext/web-inf/lib?
    This is my directory structure.
    c:tomcat in this i have
    bin
    conf
    doc
    lib
    logs
    modules
    native
    webapps
    work
    in bin there are no subdirectories
    in conf i have
    auto,jserv,jk,users
    in doc i have
    appdev,images
    sample( in appdev)
    etc,lib,src,web(in sample)
    images(in sample\web)
    in lib i have
    apps
    common
    container(c:\tomcat\lib)
    in logs,modules there are no subdirectories
    in native (c:\tomcat\native) i have
    mod_jk
    mod_jserv
    in mod_jk i have
    apache 1.3
    common
    iis
    jni
    netscape
    nt_service
    in webapps i have (c:tomcat\webapps)
    Admin,Examples,root
    in Admin i have (c:\tomcat\webapps\admin)
    contextadmin
    Meta-inf
    Test
    Web-inf
    in web-inf (c:\tomcat\webapps\admin\web-inf)
    Classes,lib,script
    in classes i have (c:\tomcat\webapps\admin\web-inf\classes)
    tadm
    in examples (c:\tomcat\webapps\examples) i have
    Images,Jsp,Meta-inf,Servlets,Web-inf
    in web-inf (c:\tomcat\webapps\examples\web-inf) i have
         Classes,jsp
    in classed (c:\tomcat\webapps\examplesweb-inf\classes) i have
    Cal
    Checkbox
    Colors
    Dates
    Error
    Examples
    Num
    Sessions
    in jsp (c:\tomcat\webapps\examples\web-inf\jsp) i have
    applet          
    I think this is enough to give correct answer for me .
    Thanks

  • Trouble connecting to MySQL databases

    So everything is in its propper place. I got to connect to a database and I get this. Over and over again, I've checked and rechecked everything several times. I just don't know what to do.
    I have Xampp installed and it works wonderfully, I just need these two to communicate with each other.
    Any solutions to this?
    Heather

    First is XAMPP running when you are trying to perform this test?
    Next, can you confirm that you are using XAMPP as a single site installation where http://localhost is the root of your website as the error is suggesting?
    If that is the case we can try to troubleshoot further, but understanding your local config is important to making sure paths are right for this to work with Dreamweaver.

  • Connection error mysql database in Dreamweaver

    the error message is - HTTP error code 404 file not found. here are some possible reasons
    screen shot - http://netwizlk.site50.net/images/DW-error.jpg
    1)there is no testing server running on the server machine.
    2)the testing server specified for this site does not map to the http://localhost/_mmServerScripts/MMhTTPDB.php verify that the URL prefix maps to the root of the site.
    guy pls help me to solve this problem. I tried several times to connect my mysql database with dreamweaver but ended up having this error I reinstalled dreamweaver cs4 and XAMPP still the error is not rectified my both remote and local files are stored in XAMPP server location called in c:\xampp\htdocs\htdocs\myweb
    anybody who could give me a speedy solution for this issue will be highly appreciated thanks alot guys.

    c:\xampp\htdocs\htdocs\myweb
    MM serverscripts must be at the root level of the virtual server, that is directly in the htdocs folder.
    Mylenium

  • How to connect mySQL database with jdbc

    Who can tell me how to connect mySQL database with jdbc? Thanks

    http://onesearch.sun.com/search/developers/index.jsp?and=connect+mysql&nh=10&phr=&qt=&not=&field=title&since=&col=devforums&rf=0&Search.x=24&Search.y=16

  • How to connect MySql database with JSP

    Dear everyone,
    how to connect MySql database with JSP......

    It's too bad that nobody has ever asked this question before...

  • I can't connect to MySQL database from The JSP Standard Tag Library

    Hi All !
    I have a problem, please help me anybody !
    I don't connect to MySQL database from jsp page using JSTL tag but from servlet all work correctly. I set my path and put �mysql-connector-java-3.1.13-bin.jar� in ENVIRONMENT WinXP(classpath=C:\Java\jdk1.5.0_10\jre\lib\ext\mysql-connector-java-3.1.13-bin.jar) and in War project folder �WEB-INF/lib� and in [TomcatServer]\common\lib.
    I have in folder�WEB-INF/lib� following files:
    antlr.jar
    commons-beanutils.jar
    commons-collections.jar
    commons-digester.jar
    commons-fileupload.jar
    commons-logging.jar
    commons-validator.jar
    jakarta-oro.jar
    jsf-api.jar
    jsf-impl.jar
    jstl.jar
    mysql-connector-java-3.1.13-bin.jar
    standard.jar
    struts.jar
    I'm using:
    NetBeans 5.5 Build200610171010 (bundled Tomcat 5.5.17)
    Ent.Pack 20061020 Visual Wb Pack 061103
    OS WinXP SP2
    Java 1.5.0_10
    MySQL 5.0.18-nt
    1:<%@page contentType="text/html"%>
    2:<%@page pageEncoding="UTF-8"%>
    8: <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    9: <%@taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>
    10:
    11: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    12: "http://www.w3.org/TR/html4/loose.dtd">
    13:
    14: <sql:setDataSource var="ds"
    15: driver="com.mysql.jdbc.Driver"
    16: url="jdbc:mysql://localhost:3306/test"
    17: user="root"
    18: password="xxxx"/>
    19:
    20:
    21:<sql:query sql="select name, age from People" var="res"
    22: dataSource="${ds}"/>
    I have received report on mistake when entered code at the top:
    �/index.jsp [21;0] According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions�
    I used instead of (dataSource="${ds}")->(dataSource="ds") but this did not work.
    After build and run I have received
    =========================================START=================================
    HTTP Status 500
    type Exception report:
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /index.jsp(21,0) According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    root cause
    org.apache.jasper.JasperException: /index.jsp(21,0) According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
    org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:955)
    org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:710)
    org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Validator.validate(Validator.java:1489)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:166)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
    Apache Tomcat/5.5.17
    =======================================END================================
    Error: "According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions" - but according to documentation such parameter possible.
    BUT WHEN JOINING With DATABASE FROM SERVLET ALL WORK FINE.
    I read this doc - [http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html], this applicable if I Tomcat Admin, but i'am not Admin
    I simply user, i.e. I want to place its database on virtual host (Tomcat+(JSP-JSTL)+MySQL).
    There is idea how can resolve this problem
    Thank you in advance ;)

    For all how have similar problem.
    Decision instead of these ways
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    it is necessary to indicate these
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

  • Error when connecting to MySQL Database

    I am trying to connect to MySQL and receive an error everytime. I have attempted to talk to Bluehost (who my site is hosted thru) and they said it is not on their end and not something they can help me with. I set up a new MySQL Database with Bluehost and then set up the site through DW and everything went fine. I secured an ftp connection and went on to connect to MySQL. When I enter in my credentials for SQL Database, it returns:
    HTTP Error Code 404:
    Reason 1. No testing server running on the server machine.
    Reason 2. Testing server specified for this site deos not map to the http://my_domain.com/_mmServerScripts/MMHTPDB.php URL. Verify the URL Prefix maps to the site.
    The testing server model I am using is set to PHP MySQL and URL Prefix I am using (my_domain.com) is my website URL. I watched a YouTube video someone suggested elsewhere on how to add MMHTTPDB.php and mysql.php files to _mmServerScripts folder since the folder is empty but unfortunately, those files are not found on my computer. I assume they were supposed to be installed when I installed DW, but they are not here. I have done a general search of the comp and looked in each folder that was installed with DW and sadly, no files that match those names. What can I do? How can I make an SQL connection? Please help. It is greatly appreciated.
    -Sharon

    Your answer can be found somewhere in here http://forum.wampserver.com/read.php?2,83382,88694
    My hosts file (c:\windows\system32\drivers\etc\hosts) looks like
    # Copyright (c) 1993-2009 Microsoft Corp.
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    # For example:
    #      102.54.94.97     rhino.acme.com          # source server
    #       38.25.63.10     x.acme.com              # x client host
    # localhost name resolution is handled within DNS itself.
        127.0.0.1       localhost
        ::1             localhost

  • Is it possible to insert data into a MySQL database with Java?

    Hello everyone!
    I would like to know, if it's possible to insert data into a MySQL database, with a JFrame inside a servlet?
    When the JFrame is first created it calls this method:
         * Connects the servlet with the MySQL database.
        private void connect(){
            try{
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/data", "root", "omfg123");
            }catch(ClassNotFoundException cnfe){
                cnfe.printStackTrace();
            }catch(SQLException sqle){
                sqle.printStackTrace();
        }Then, when you click the "Add" button, it executes this code:
                add.addActionListener(new ActionListener(){
                    @Override
                    public void actionPerformed(ActionEvent ae){
                        String employee = employeeName.getText();
                        String[] args = employee.split(" ");
                        firstName = args[0];
                        lastName = args[1];
                        execute();
                });And this is my "execute()" method:
         * Connects the servlet with the MySQL database.
         * - And executes the SQL queries.
        private void execute(){
            try{
                PreparedStatement statement = connection.prepareStatement("insert" +
                        " into employees values(" + firstName + ", " + lastName
                        + ")");
                ResultSet result = statement.executeQuery();
                String fullName = firstName + " " + lastName;
                printer.write("Employee " + fullName + " added.</br>");
            }catch(SQLException sqle){
                sqle.printStackTrace();
        }But when I click the "Add" button, nothing happens.

    This is what I use to insert into mysql. It works on windows.
    try {
                Class.forName("com.mysql.jdbc.Driver");
                String connectionUrl = "jdbc:mysql://" + loadip + "/custsig?" +
                        "user=root&password=";
                Connection con = DriverManager.getConnection(connectionUrl);
                newproc = jTextField1.getText();
                newsoft = jTextField2.getText();
                newdeb = jTextField3.getText();
                newcust = jTextField4.getText();
                if (newcust.equals("")) {
                    errorsig12 = 1;
                    jLabel1.setForeground(new java.awt.Color(255, 0, 0));
                } else if (newsoft.equals("")) {
                    errorsig12 = 1;
                    jLabel2.setForeground(new java.awt.Color(0, 0, 0));
                } else if (newproc.equals("")) {
                    errorsig12 = 1;
                    jLabel3.setForeground(new java.awt.Color(0, 0, 0));
                } else if (newdeb.equals("")) {
                    errorsig12 = 1;
                    jLabel4.setForeground(new java.awt.Color(0, 0, 0));
                if (errorsig12 == 0) {
                    PreparedStatement ps = con.prepareStatement("insert into customer set cust_name = ?,  software = ?, processor = ?, debit = ?");
                    ps.setString(4, newdeb);
                    ps.setString(3, newproc);
                    ps.setString(2, newsoft);
                    ps.setString(1, newcust);
                    int rs = ps.executeUpdate();
            } catch (SQLException eg) {
                System.out.println("SQL Exception: " + eg.toString());
            } catch (ClassNotFoundException cE) {
                System.out.println("Class Not Found Exception: " + cE.toString());
            }

  • Connecting to mysql database using DBLOGIN

    I am trying to connect to a mysql database through GG command interface and am unable to get the DBLOGIN to work correctly. Here is what I am getting:-
    mysql world -u root -p<password> (as user OS user mysql- works!)
    GGSCI (rac1) 5> DBLOGIN SOURCEDB world, USERID root, PASSWORD <password>
    2010-11-08 16:29:17 WARNING OGG-00769 MySQL Login failed: . SQL error (2002). Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2).
    ERROR: Failed to connect to MySQL database engine for HOST localhost, DATABASE world, USER root, PORT 0.
    I am not too familiar with mysql and will appreciate help and also pointer to documents that walk through setting up and testing Golden Gate with mysql.
    Thanks,
    Satish

    hi.
    i have same problem can't connect to mysql using dblogin on ggsci, please helpme
    this my.cnf configuration
    # Example MySQL config file for small systems.
    # This is for a system with little memory (<= 64M) where MySQL is only used
    # from time to time and it's important that the mysqld daemon
    # doesn't use much resources.
    # You can copy this file to
    # /etc/my.cnf to set global options,
    # mysql-data-dir/my.cnf to set server-specific options (in this
    # installation this directory is /var/lib/mysql) or
    # ~/.my.cnf to set user-specific options.
    # In this file, you can use all long options that a program supports.
    # If you want to know which options a program supports, run the program
    # with the "--help" option.
    # The following options will be passed to all MySQL clients
    [client]
    #password     = your_password
    port          = 3306
    socket          = /tmp/mysql.sock
    #socket = /var/run/mysqld/mysqld.sock
    # Here follows entries for some specific programs
    # The MySQL server
    [mysqld]
    port          = 3306
    socket = /tmp/mysql.sock
    #socket          = /var/run/mysqld/mysqld.sock
    skip-locking
    key_buffer_size = 16K
    max_allowed_packet = 1M
    table_open_cache = 4
    sort_buffer_size = 64K
    read_buffer_size = 256K
    read_rnd_buffer_size = 256K
    net_buffer_length = 2K
    thread_stack = 128K
    # Don't listen on a TCP/IP port at all. This can be a security enhancement,
    # if all processes that need to connect to mysqld run on the same host.
    # All interaction with mysqld must be made via Unix sockets or named pipes.
    # Note that using this option without enabling named pipes on Windows
    # (using the "enable-named-pipe" option) will render mysqld useless!
    #skip-networking
    server-id     = 1
    # Uncomment the following if you want to log updates
    #log-bin=mysql-bin
    # binary logging format - mixed recommended
    #binlog_format=mixed
    # Uncomment the following if you are using InnoDB tables
    #innodb_data_home_dir = /var/lib/mysql/
    #innodb_data_file_path = ibdata1:10M:autoextend
    #innodb_log_group_home_dir = /var/lib/mysql/
    # You can set .._buffer_pool_size up to 50 - 80 %
    # of RAM but beware of setting memory usage too high
    #innodb_buffer_pool_size = 16M
    #innodb_additional_mem_pool_size = 2M
    # Set .._log_file_size to 25 % of buffer pool size
    #innodb_log_file_size = 5M
    #innodb_log_buffer_size = 8M
    #innodb_flush_log_at_trx_commit = 1
    #innodb_lock_wait_timeout = 50
    [mysqldump]
    quick
    max_allowed_packet = 16M
    [mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates
    [myisamchk]
    key_buffer_size = 8M
    sort_buffer_size = 8M
    [mysqlhotcopy]
    interactive-timeout

  • MySQL database with SQL Toolkit

    Hi,
    we are using CVI 2012 and the SQL Toolkit 2.2 and we want to connect to a MySQL database.
    The MySQL database was created with MySQLServer. When we try to connect with DBConnect we get an error.
    How can we connect the MySQL Database?
    What do we have to type in the connection string in DBConnect? Is it the name of the database, the path to the database or anything else?
    Does any one have experience with the SQL toolkit?
    Thanks in advance
    Oliver
    Solved!
    Go to Solution.

    You need to install the mysql connector odbc and then create an ODBC dns for your database.
    control panel, administrative, odbc

  • Try to use Mysql database with forte

    Dear All:
    As title said, I try to use Mysql database with forte.
    I read the manual , it said I have to put the database jdbc driver in
    the Forte for Java lib/ext directory.
    I did it and then add a new Driver in the Runtime tab in the Explorer
    window .
    But when I try to test this new driver(by Right-clicking on the driver
    or connection in the Explorer and select Test Driver from the context
    menu),it said "cannot find driver class: check your CLASSPATH or
    \lib\ext direectory".
    I am sure I'hve put the driver class(with the whole directory structure)
    in that folder.
    Does anyone what I may go wrong ?
    Could you please give me some advices that I can fix this problem ?
    Thanks in advance.
         Ken @ Taipei , Taiwan , Asia

    You should have put the jar file that contains the driver into that directory. If you unpacked the jar file and put the individual classes into that directory, it will not work.

  • Can I connect to MySQL database

    sorry for my English...
    I'm absolutely new in Flex
    can I connect to MySQL database?
    I read here that I need to create a java class file and edit
    an xml to create connection to oracle, can I connect to MySQL
    server too, I think that the PHP-XML is too slow to work with lare
    amounts of data... so can you post me MXML, the XML, and the JAVA
    class file, with I will be able to send sql to mysql server and get
    the response?
    or FDS is a stand-alone SQL server?

    Flex is not a SQL server.
    The Flex SDK and compiler supports developing applications
    that run in the Flash player.
    Flex Data Services is deployed as a Java web application that
    simplifies integrating Flex clients with Java server-side resources
    (including interacting with SQL databases via Java).
    FlexBuilder is an IDE for developing Flex apps.
    I'd recommend spending some time browsing the Flex product
    area on adobe.com.
    Best,
    Seth

  • Cs3 connect to mysql database

    hi,
    i am having problems with my xp machine running cs3. when i try to connect to mysql database it throws back http error code 405 method not allowed.
    i downloaded the script replacement files after googling however that still never resolved the issue. can anyone help?
    many thanks

    This may, or may not, help...
    For those using MySQL - Installing PHP and MySQL on Windows
    XP
    http://www.webassist.com/professional/products/solutionrecipes.asp

Maybe you are looking for

  • How can i move photos from my iphone to my pc

    Hi all Please help! Im trying to transfer photos from my iphone 4s to my pc and i havent a clue how! Can someone please give me an idiots guide about how to do this! Regards James

  • Error message in an Adobe Reader PDF document

    "There is a problem with Adobe Acrobat/Reader. If it is running, please exit and try again. (0:104)." We have exited, reopened the file many times and have rebooted many time, but get same error.  The PDF file continues to refuse to download.  Any id

  • How to insert multiple records in a single query

    Dear all, Can you please tell how to insert multiple records in a single query ??

  • Standard Algorithms in Java

    Hello everone, does someone of you know a collection of standard algorithms programmed in Java where you can download the examples (a kind of library or documentation) We are trying to standardize our code (e.g. complex loops and conditions) and this

  • Aperture Raw & Jpeg import Problem

    I'm on the current Aperture and face the following situation: I have a memory card containing photos shot partly as jpeg-only and partly as jpeg&raw. No problem one should think since Aperture has the option to only import either raw or jpeg if there