Connecting to MySQL from an Applet
Hi !
I have some serious Problem connecting from within my Applet to a MySQL-DB. Everything is fine until i try to establish a Connection ( I use mm.mysql-driver ). The Driver seems to be correctly loaded, but when it comes to connection I get the following Error : Connection failed, Are you sure, that there is a MySQL-Database running at the specified target bla bla bla .....
I guess, that it is some Problem with the Applet not beeing certified, but as it is only intended for INTRAnet use, I don't really care about security. Has anybody a quick workaroud for my Problem ?
Thanx in advance
Regards
Markward Schubert
i would try to connect to that database with application, if that fails as well then there is no applet certification problem
usually this kind of error is printed when you try to connect to some database that is not there
and with an applet you need to put applets binaries and database in the same server, because applet can connect only to the host where from it was loaded
i hope that some of it helped
L.
Similar Messages
-
JDBC connection to derby from an applet
I'm doing the JDBC tutorial at java.sun.com
Everything runs fine from the Netbeans IDE. I'm not sure whether the applet is supposed to work inside the IDE or not, I figure that's meant for the web.
Within Netbeans, the following URL works:
String url = "jdbc:derby:C:\\Documents and Settings\\HP_Administrator\\.netbeans-derby\\helpme";
When I load a webpage with the applet, I get:
java.SQLException: No suitable driver found for jdbc:derby:C:\Documents and Settings\HP_Administrator\.netbeans-derby\helpme.
Now, I know it found the driver Class, otherwise I would have gotten Class Not Found -- so I assume its just not making the connect to the database from the applet.
I have tried many formats for the url --
String url = "jdbc:derby://localhost:1527/C:\\Documents and Settings\\HP_Administrator\\.netbeans-derby\\helpme";
String url = "jdbc:derby://localhost:1527/helpme";
String url = "jdbc:derby:helpme";
Nothing I've tried has worked. Can someone point me in the right direction please?
Everything is running on the same machine."No suitable driver" is an error message which can indicate an improper URL. And in your case, you will want to avoid including any reference to the C: drive in your url. The format for the url can also depend upon the database you are using. So for example an mysql url would begin with
jdbc:mysql://localhost:3306
String url = "jdbc:derby://localhost:1527/helpme";This suggestions that you may be using a database server called derby which utilizes port 1527 and that your particular database is called helpme.
In any case you will want to look at documentation for your particular database software ( MSAccess, MySQL, Oracle etc ) to determine how to construct the url. -
Can't connect to MySQL from Oracle 11g R1
Hello Oracle's guru.
Sorry for my English it's not my native langauge
Enviroments: Oracle 11g R1, Windows 7, ODBC Driver 5.1.8
I have a some problem with creation gateway to connection to MySQL, and I hope somebody can help me.
So,
1) ODBC name - MYSQLDSN
2) initMYSQLDSN.ora
# This is a sample agent init file that contains the HS parameters that are
# needed for the Database Gateway for ODBC
# HS init parameters
HS_FDS_CONNECT_INFO = MYSQLDSN
HS_FDS_TRACE_LEVEL = 0
3) listener.ora
# listener.ora Network Configuration File: E:\app\voxa\product\11.1.0\db_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=MYSQLDSN)
(ORACLE_HOME=E:\app\voxa\product\11.1.0\db_1)
(PROGRAM=dg4odbc)
4) tnsnames.ora
# tnsnames.ora Network Configuration File: E:\app\voxa\product\11.1.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
CXWH =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = CXWH)
MYSQLDSN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =(SID = MYSQLDSN))
(HS = OK)
Then I trying to connect to MySQL using sql*plus:
C:\Windows\system32>sqlplus
SQL*Plus: Release 11.1.0.6.0 - Production on Ср Июн 1 12:13:39 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
login: system
pass:
Connect to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create public database link MYSQLDSN
2 connect to DEMO identified by "DEMO" using 'MYSQLDSN';
Channel was created
SQL> select * from items@MYSQLDSN;
select * from items@MYSQLDSN
Error in line 1:
ORA-28500: connection with ORACLE with other system return message:
[MySQL][ODBC 5.1 Driver][mysqld-5.5.12]You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right
syntax to use near
'"ITEMS_KEY",A1."ITEM_NAME",A1."ITEM_CATEGORY",A1."ITEM_VENDOR",A1."ITEM_SKU",A1
.' at line 1
ORA-02063: предшествующий 2 lines из MYSQLDSN
If I trying create new ODBC mobule via OWB, I had next error:
[MySQL][ODBC 5.1 Driver][mysqld-5.5.12]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"DUAL"' at line 1
ORA-02063: предшествующий 2 lines из OWB_56
What I do wrong? Please help meHi,
You can download the 11.1.0.7 patchset from My Oracle Support -
support.oracle.com
as patch 6890831.
Once logged in click on 'Patches and Updates' and enter the patch number as 6890831 and choose whichever platform you are running.
the readme explains how to apply the patch to an existing 11.1.0.6 install.
The url you posted is only for complete product installs, but 11.1.0.7 is only a patchset that must be applied to an existing install.
Regards,
Mike -
Connecting to MySQL from Sun One Studio
Hi,
I am trying to connect to the MySQL from the Sun One Studio 5. I followed these steps.
1. I downloaded the MySQL software and installed on my local computer, it was successful.
2. I got the drivers [b][b][b]mysql-connector-java-3.0.8-stable-bin.jar and placed it in the <stdudio5>/lib/ext/ directory.
3. And I successfully got through that one also, and in the database section it showed me the icon for connecting to mysql database. I gave the url, username, and password. It worked fine.
4. Then I created the connection pool, JDBC resource, and Persistence manager for my server instance. It was also successful.
5. When I built a cmp bean accessing the table in mySQL database, it is giving me these errors.
If you notice these error, it is asking for vendor type. But i don't have any option to choose the vendor type when i configured the database resources.
Can soem body suggest some other method and clear this error. I am struggling with this since a week.
Thank you.
[[b]09/Oct/2003:11:12:31] WARNING ( 3476): Cannot get database metadata: database product name.
java.sql.SQLException: com.sun.enterprise.repository.J2EEResourceException
java.lang.ClassNotFoundException: org.gjt.mm.mysql.jdbc2.optional.MysqlDataSource
at com.sun.enterprise.resource.SystemJdbcDataSource.internalGetConnection(SystemJdbcDataSource.java:252)
at com.sun.enterprise.resource.SystemJdbcDataSource.getConnection(SystemJdbcDataSource.java:154)
at com.sun.jdo.spi.persistence.support.sqlstore.ejb.TransactionHelperImpl.getConnection(TransactionHelperImpl.java:171)
at com.sun.jdo.spi.persistence.support.sqlstore.ejb.EJBHelper.getConnection(EJBHelper.java:169)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getDBName(SQLPersistenceManagerFactory.java:781)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getFromPool(SQLPersistenceManagerFactory.java:709)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getPersistenceManager(SQLPersistenceManagerFactory.java:598)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:770)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:660)
at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.jdoGetPersistenceManager(JobinfoBean_1956195957_ConcreteImpl.java:1479)
at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.ejbFindByTitle(JobinfoBean_1956195957_ConcreteImpl.java:541)
at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.findByTitle(JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.java:175)
at JAdminEntityBeans._JobinfoHome_Stub.findByTitle(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.forte4j.j2ee.ejbtest.webtest.InvocableMethod$MethodIM.invoke(InvocableMethod.java:231)
at com.sun.forte4j.j2ee.ejbtest.webtest.EjbInvoker.getInvocationResults(EjbInvoker.java:96)
at com.sun.forte4j.j2ee.ejbtest.webtest.DispatchHelper.getForward(DispatchHelper.java:189)
at jasper.dispatch_jsp._jspService(_dispatch_jsp.java:136)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
[09/Oct/2003:11:12:31] INFO ( 3476): Bean Jobinfo method ejbFindByTitle: problems running JDOQL query.
com.sun.jdo.api.persistence.support.JDOFatalInternalException: Failed to get the vendor type for the data store.
NestedException: java.sql.SQLException: com.sun.enterprise.repository.J2EEResourceException
java.lang.ClassNotFoundException: org.gjt.mm.mysql.jdbc2.optional.MysqlDataSource
at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getDBName(SQLPersistenceManagerFactory.java:802)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getFromPool(SQLPersistenceManagerFactory.java:709)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getPersistenceManager(SQLPersistenceManagerFactory.java:598)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:770)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:660)
at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.jdoGetPersistenceManager(JobinfoBean_1956195957_ConcreteImpl.java:1479)
at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.ejbFindByTitle(JobinfoBean_1956195957_ConcreteImpl.java:541)
at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.findByTitle(JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.java:175)
at JAdminEntityBeans._JobinfoHome_Stub.findByTitle(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.forte4j.j2ee.ejbtest.webtest.InvocableMethod$MethodIM.invoke(InvocableMethod.java:231)
at com.sun.forte4j.j2ee.ejbtest.webtest.EjbInvoker.getInvocationResults(EjbInvoker.java:96)
at com.sun.forte4j.j2ee.ejbtest.webtest.DispatchHelper.getForward(DispatchHelper.java:189)
at jasper.dispatch_jsp._jspService(_dispatch_jsp.java:136)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)The AS7 error suggests that you have not set up the server startup classpath to include the driver jar. The steps to do this are included in the article mentioned in Chris's reply, namely:
http://developers.sun.com/tools/javatools/tips/tip03-08-22.html
Note especially the part starting with Step 3 under the section "Enabling the JDBC Driver in the IDE."
-Jane -
Problem to connect to mysql from servlet using a javabean
Hi,
I'm new here and beginner on java to.
I have problem to connect to MySql database, by a connection javabean.
It's the following: a HTML page calls a servlet and this servlet imports the package connection javabean.
It has no problem when I establish the connection inside the servlet, with all its methods (public and private). But i want to separate the code connection from servlet.
Detail: there is no problem, using the javabean to connect to MS Access database.
I put "mysql-connector-java-3.1.12-bin.jar" file inside WEB-INF/lib application and common/lib directories.
I set the classpath:
SET CLASSPATH=%CATALINA_HOME%\COMMON\LIB\mysql-connector-java-3.1.12-bin.jar;%CLASSPATH%
I think that the servlet cannot create an instance of javabean, because passed by catch exception of the servlet init method.
But I don't know why.
Please Why?
Below there are the fragment of errors, servlet code e javabean code.
Thank you.
Zovao.
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at CadServletFileBeanConexArq.doPost(CadServletFileBeanConexArq.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
Note: The line 47 is calling insertIntoDB javabean method.
========///////////////===============
// Here is the servlet CadServletFileBeanConexArq.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import conJdbc.*;
public class CadServletFileBeanConexArq extends HttpServlet {
public ConexPed connect = null;
private String driver = "com.mysql.jdbc.Driver";
private String URL = "jdbc:mysql://localhost:3306/cadastro";
public void init( ServletConfig config )
throws ServletException
super.init( config );
try
connect = new ConexPed(driver, URL, "monty", "some_pass");
catch ( Exception e )
e.printStackTrace();
connect = null;
public void doPost( HttpServletRequest req,
HttpServletResponse res )
throws ServletException
boolean success = true;
String email, nome, sobrenome, produto, valor;
email = req.getParameter( "Email" );
nome = req.getParameter( "Nome" );
sobrenome = req.getParameter( "Sobrenome" );
produto = req.getParameter( "Produto" );
valor = req.getParameter( "Valor" );
res.setContentType( "text/html" );
if ( email.length() > 0 && nome.length() > 0 && sobrenome.length() > 0 && valor.length() > 0 )
/* inserting data */
success = connect.insertIntoDB(
"'" + email + "','" + nome + "','" + sobrenome + "','" + produto + "'", Double.parseDouble(valor) );
//closing connection
public void destroy()
connect.fecharConexao();
=============///////////////============
Here is the JavaBean.
package conJdbc;
import java.sql.*;
public class ConexPed
public Connection connection;
public Statement statement;
public ConexPed (String driver, String urlServidor, String user, String password)
try
Class.forName(driver);
connection = DriverManager.getConnection(urlServidor,user,password);
catch (ClassNotFoundException ex)
System.out.println("N�o foi poss�vel encontrar a classe do Driver: " + driver);
catch (SQLException ex)
System.out.println("N�o foi poss�vel conectar ao servidor");
try
statement = connection.createStatement();
catch (SQLException ex)
System.out.println("N�o foi poss�vel criar a statement");
*Inserting data to database
public synchronized boolean insertIntoDB( String stringtoinsert, double valor)
try
statement.executeUpdate( "INSERT INTO pedido values (" + stringtoinsert + " , " + valor + ");" );
catch ( Exception e ) {
System.err.println(
"ERROR: Problemas ao adicionar nova entrada" );
e.printStackTrace();
return false;
return true;
* Close statement.
public void fecharStatement()
try
statement.close();
catch (SQLException ex)
ex.printStackTrace();
* close database
public void fecharConexao()
try
connection.close();
catch (SQLException ex)
ex.printStackTrace();
}Hi,
I'm new here and beginner on java to.
I have problem to connect to MySql database, by a connection javabean.
It's the following: a HTML page calls a servlet and this servlet imports the package connection javabean.
It has no problem when I establish the connection inside the servlet, with all its methods (public and private). But i want to separate the code connection from servlet.
Detail: there is no problem, using the javabean to connect to MS Access database.
I put "mysql-connector-java-3.1.12-bin.jar" file inside WEB-INF/lib application and common/lib directories.
I set the classpath:
SET CLASSPATH=%CATALINA_HOME%\COMMON\LIB\mysql-connector-java-3.1.12-bin.jar;%CLASSPATH%
I think that the servlet cannot create an instance of javabean, because passed by catch exception of the servlet init method.
But I don't know why.
Please Why?
Below there are the fragment of errors, servlet code e javabean code.
Thank you.
Zovao.
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at CadServletFileBeanConexArq.doPost(CadServletFileBeanConexArq.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
Note: The line 47 is calling insertIntoDB javabean method.
========///////////////===============
// Here is the servlet CadServletFileBeanConexArq.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import conJdbc.*;
public class CadServletFileBeanConexArq extends HttpServlet {
public ConexPed connect = null;
private String driver = "com.mysql.jdbc.Driver";
private String URL = "jdbc:mysql://localhost:3306/cadastro";
public void init( ServletConfig config )
throws ServletException
super.init( config );
try
connect = new ConexPed(driver, URL, "monty", "some_pass");
catch ( Exception e )
e.printStackTrace();
connect = null;
public void doPost( HttpServletRequest req,
HttpServletResponse res )
throws ServletException
boolean success = true;
String email, nome, sobrenome, produto, valor;
email = req.getParameter( "Email" );
nome = req.getParameter( "Nome" );
sobrenome = req.getParameter( "Sobrenome" );
produto = req.getParameter( "Produto" );
valor = req.getParameter( "Valor" );
res.setContentType( "text/html" );
if ( email.length() > 0 && nome.length() > 0 && sobrenome.length() > 0 && valor.length() > 0 )
/* inserting data */
success = connect.insertIntoDB(
"'" + email + "','" + nome + "','" + sobrenome + "','" + produto + "'", Double.parseDouble(valor) );
//closing connection
public void destroy()
connect.fecharConexao();
=============///////////////============
Here is the JavaBean.
package conJdbc;
import java.sql.*;
public class ConexPed
public Connection connection;
public Statement statement;
public ConexPed (String driver, String urlServidor, String user, String password)
try
Class.forName(driver);
connection = DriverManager.getConnection(urlServidor,user,password);
catch (ClassNotFoundException ex)
System.out.println("N�o foi poss�vel encontrar a classe do Driver: " + driver);
catch (SQLException ex)
System.out.println("N�o foi poss�vel conectar ao servidor");
try
statement = connection.createStatement();
catch (SQLException ex)
System.out.println("N�o foi poss�vel criar a statement");
*Inserting data to database
public synchronized boolean insertIntoDB( String stringtoinsert, double valor)
try
statement.executeUpdate( "INSERT INTO pedido values (" + stringtoinsert + " , " + valor + ");" );
catch ( Exception e ) {
System.err.println(
"ERROR: Problemas ao adicionar nova entrada" );
e.printStackTrace();
return false;
return true;
* Close statement.
public void fecharStatement()
try
statement.close();
catch (SQLException ex)
ex.printStackTrace();
* close database
public void fecharConexao()
try
connection.close();
catch (SQLException ex)
ex.printStackTrace();
} -
How to connect to mysql from java app
hi
please say the procedure for connecting to mysql database from java app.
.) what should i give in environmental variables
.)where can i find the driver class for the mysql
.) syntax of the url
eg:- DM.getConnection("jdbc:mysql:..............what comes here..............");You can also get connections from a DataSource. Simple example:
MysqlDataSource msds = new MysqlDataSource();
msds.setUrl("jdbc:mysql://127.0.0.1:3306/dbdame");
msds.setUser("user");
msds.setPassword("pass");
Connection c = msds.getConnection();Explore your options and be sure to consider connection pooling. -
Can't connect to MySQL from Flex
Hi,
I just started learning Flex a week ago and I'm still a noob
in this area.
I recently discovered about Cairngorm and tried to understand
it.
I managed to understand the Cairngorm diagram and applied
that in my "Login" function.
My problem is when I define a database connection to MySQL, I
would get error in my Flex application, but when i define static
variable the whole application would work just fine.
The error is "NetConnection.call.failed: HTTP:failed"
I'm using Zend Amf as the server.
Please tell me what is the problem. Thanks!
Regards,
Joni
============ Edit ================
I'm sorry,
I just did some fix and this is the more specific details.
If I use this code in my PHP
mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);
$query = "SELECT * FROM school";
$result = mysql_query($query);
return "test";
Flex would be able to "get" the return value.
But if I used this code
mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);
$query = "SELECT * FROM school";
$result = mysql_query($query);
return $result;
Flex would get an error.
Please help.
Thanks.
Regards
JoniI am not a php guy really so here is what I would do in this
situation. Using the Flex Builder data wizard, I would generat a
crud appliation against the mySQL table and see how the resulting
php code returns data back to flex.
HTH
STeveR -
"UnknownHost" exception while connecting to mysql from web dynpro
Hi
I am trying to connect to Mysql 5.0 database from web dynpro application.I am using NWDS 7.1.
I have followed this blog and created the datasource in NWA.
https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/8675
I have written the following code in my web dynpro application.
InitialContext ctx;
try{
ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("jdbc/dbconnect");
Connection conn=ds.getConnection();
wdComponentAPI.getMessageManager().reportSuccess("connected");
Statement stmt=conn.createStatement();
String query="select Col from TestTable";
ResultSet res=stmt.executeQuery(query);
while(res.next())
String str1=res.getString(1);
wdComponentAPI.getMessageManager().reportSuccess(str1);
}catch (Exception e) {
wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());
// TODO: handle exception
But I m getting the following error as "UnknownHost exception"
I checked with the datasource created in NWA.Here in the Driver status it is showing the driver as unknown.
I have added the following driver.
mysql-connector-java-5.0.8-bin.jar
Any idea on how to solve this problem?
Do I need to add the driver in my application also.
Thanks in advance,
SumangalaHi,
Have you created a datasource in Visualadmin?
Was that tested and was it success full?
If you havent done this this could be your issue
make sure the following code is using the correct datasource
DataSource ds=(DataSource)ctx.lookup("jdbc/dbconnect");
Regards
Ayyapparaj -
Unable to connect to MySql from eclipse
Hi,
I searched a number of threads and forums but was unable to find the reason for this issue. Please find my code belo.
import java.sql.Connection; import java.sql.DriverManager; public class MySql { /** * @param args */ /** * @param args */ /** * @param args */ public static void main (String[] args) { Connection conn = null; try { String userName = "root"; String password = "secret"; String url = "jdbc:mysql://locahost:3306/test"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); if(!conn.isClosed()) System.out.println("Successfully connected to " + "MySQL server using TCP/IP..."); } catch (Exception e) { System.out.println(e.getLocalizedMessage()); } } }
I added the mysql connector in the build path of eclipse but it still doesn't work.
It gives Communication Link Failure Exception or sometimes com.mysql.jdbc.Driver
I am able to connect to the server thru the GUI tool of MySql. I created the dsn in windows with name test using the MySql driver.
Please help me out.public static void main (String[] args)
Connection conn = null;
try
String userName = "root";
String password = "secret";
String url = "jdbc:mysql://locahost:3306/mydbtest";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
//String url = "jdbc:odbc:mydbtest";
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
if(!conn.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
catch (Exception e)
System.out.println(e.printStackTrace());
}Stack trace below
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2260)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:787)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:357)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MySql.main(MySql.java:30)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2181)
... 12 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:293)
... 13 more -
Hi
How to configure any connection from SAP to MySQL, I want to use result in ABAP.
I heard about legacy JDBC to MySQL but which transaction is for this ? and what I need? Netveawer and somehitng more?
Edited by: Kosmo on Oct 20, 2009 10:43 AMIt isn't possible
-
Connecting to MySQL from another machine.
I use following code to connect to my database.it works
String databaseUrl = "jdbc:mysql://localhost:3306/test";
but when i use
String databaseUrl = "jdbc:mysql://192.168.0.205:3306/test";{
it gives error (192.168.0.205 being my ip address)
error
message from server : "Host TRAIN5" is not allowed to connect to this MySQL server.
Is that because of my connection string?It is because of your configuration. It has to do with user permission.
Read the MySQL manual, again (you have read it, haven't you?), and pay close attention to user administration and the "GRANT" statement. -
Connecting to MYSQL from RMI Server results SQL Communication fail
Hi ,
I have an RMI Server which exports a remote method, which in-turn needs to access content
from the MYSQL Database.
PROBLEM: The code snip for RMI Server is given below. In this getChief() is the remote method called
by the RMI Client running on my same Windows XP machine (ie., localhost).
I get a slew of exceptions when the DriverManager.getConnection() API call occurs in getChief()
via the remote method call from the RMI Client. Two exceptions are the SQL Communications failure and Access Denied Socket Exceptions.
I checked my policy file is OK and MySQL Server is running and my username/password is right in code?
Can you please let me know what am I missing in the RMI Server code?
I also found my code works if the Database Connection API is used within main() rather than inside a Remote
Method...
The Source and Binary are available in my local Windows XP Machine
RMI Server: c:/workspace/DirectoryJava/src/server for and c:/workspace/DirectoryJava/bin/server
RMI Client: c:/workspace/DirectoryJava/src/client for and c:/workspace/DirectoryJava/bin/client
My security policy file is:
grant codeBase "file:/workspace/DirectoryJava/bin" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "listen,connect,accept,resolve";
permission java.net.SocketPermission "*","listen,connect,accept,resolve";
grant codeBase "file:/workspace/DirectoryJava/bin/client" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "listen,connect,accept,resolve";
permission java.net.SocketPermission "*","listen,connect,accept,resolve";
grant codeBase "file:/workspace/DirectoryJava/bin/server" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "listen,connect,accept,resolve";
permission java.net.SocketPermission "*","listen,connect,accept,resolve";
grant codeBase "file:/workspace/DirectoryJava/bin/directory" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "listen,connect,accept,resolve";
permission java.net.SocketPermission "*","listen,connect,accept,resolve";
grant codeBase "file:/workspace/DirectoryJava/src/client" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "listen,connect,accept,resolve";
permission java.net.SocketPermission "*","listen,connect,accept,resolve";
grant codeBase "file:/workspace/DirectoryJava/src/server" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "listen,connect,accept,resolve";
permission java.net.SocketPermission "*","listen,connect,accept,resolve";
grant codeBase "file:/workspace/DirectoryJava/src/directory" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "listen,connect,accept,resolve";
permission java.net.SocketPermission "*","listen,connect,accept,resolve";
};I checked that mysqld.exe is running at port 3306 and am able to connect to and use it via
MySQL Command Client successfully.
Thanks in advance.
The Exception list is pasted below.
c:\workspace\DirectoryJava\bin>java -cp "c:/workspace/Directory
Java/bin/Directory.jar;c:/workspace/DirectoryJava/bin/server;c:/workspac
e/DirectoryJava/bin;C:/Program Files/MySQL/mysql-connector-java-5.1.6/my
sql-connector-java-5.1.6-bin.jar" -Djava.rmi.server.codebase=file:/c:/workspace/
DirectoryJava/bin/Directory.jar -Djava.security.policy=wideopen.policy
server.DirectoryEngine
DirectoryEngine bound
getChief() Called
SQLException: Communications link failure
Last packet sent to the server was 0 ms ago.
SQLState: 08S01
VendorError: 0
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai
lure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1
074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at server.DirectoryEngine.getChief(DirectoryEngine.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Sou
rce)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
ce)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: java.security.AccessControlException: acces
s denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndT
hrowIt(StandardSocketFactory.java:404)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.ja
va:265)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
... 26 moreCODE SNIP:
=========
public class DirectoryEngine implements Directory {
public DirectoryEngine() {
super();
public Employee getChief() throws RemoteException {
Statement stmt = null;
ResultSet rs = null;
Employee emp = null;
// TODO Auto-generated method stub
try {
System.out.println("getChief() Called");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306",
"<username>","<password>");
// Username and Password were replaced with root username and password in my original code
System.out.println("getConnection() Called");
stmt = conn.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
System.out.println("createStatement() Called");
rs = stmt.executeQuery("use mysql");
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
// it is a good idea to release
// resources in a finally{} block
// in reverse-order of their creation
// if they are no-longer needed
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlEx){
// ignore
rs = null;
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlEx) {
// ignore
stmt = null;
return emp;
} /* getChief() ends */
public static void main(String[] args) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
try {
String name = "Directory";
Directory engine = new DirectoryEngine();
Directory stub =
(Directory) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub);
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("DirectoryEngine bound");
} catch (Exception e) {
System.err.println("DirectoryEngine exception:");
e.printStackTrace();
} /* end DirectoryEngine class */It looks there is some permission issue.
Can you please try once with below policy and let me know the result.
grant {
permission java.security.AllPermission;
}; -
Connect to mysql in another machine
Hi, there,
I have two database. One is oracle in my local machine, another is mysql in another machine. Now, I made a jsp program to control the two database concurrently. When I connect to mysql, I got errors:
Internal Servlet Error:
javax.servlet.ServletException: Server configuration denies access to data source
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at jspForOracle._0002fjspForOracle_0002fmodiProcess_0002ejspmodiProcess_jsp_1._jspService(_0002fjspForOracle_0002fmodiProcess
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java)
My local machine is : Redhat7.1, tomcat and oracle
Mysql machine is : Slackware, tomcat and mysql
I can ping and ssh the mysql machine. And I grant the mysql table for the permission to access the table. But still the same thing. What the problem?
Thank you in advance
peterin your error message:
javax.servlet.ServletException: Server configuration denies access to data source
The server being referred to is the mysql server. Mysql has uid and password like all db's, but in addition, it has security that is sensitive to the source of the connection. Just because you have a valid uid and password doesn't mean that you will be able to connect from anywhere.
This data is in the user table of the mysql database, which is included by default in every mysql installation. What you need to do is edit the privileges of the user account that you're using to connect to mysql from the jsp. There is some good documetation on user administration here:
http://www.mysql.com/documentation/mysql/bychapter/ -
How do i make http connection from an applet to a servlet
i am not able to make a http connection from the applet to servlet
my code for servlet is as follows
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class newDatabaseServlet extends HttpServlet {
// Connection con;
// Statement stmt;
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/content");
System.out.println("megha");
String mthd[] = req.getParameterValues("event");
System.out.println(mthd.length);
System.out.println(mthd);
System.out.println(req.getQueryString());
// System.out.println("megha");
PrintWriter fw = new PrintWriter(new FileOutputStream(new File("e:/JRun/servers/default/default-app/mycontent.txt")));
String s = "this text comes from servlet";
fw.print(s);
fw.flush();
if(mthd[0].equalsIgnoreCase("callEditor")) {
openEditor(req,resp);
public void openEditor(HttpServletRequest req, HttpServletResponse resp) {
/* try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@pc6:1521:oradba","test","test");
catch(Exception e) {
e.printStackTrace();
try {
resp.sendRedirect("/RunApp1.html");
catch(IOException e) {
e.printStackTrace();
/*try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@pc6:1521:oradba","test","test");
catch(Exception e) {
e.printStackTrace();
resp.setContentType("text/html");
PrintWriter output = resp.getWriter();
try {
stmt = con.createStatement();
String strContent = "select * from edTable where newsid = 2";
ResultSet rs = stmt.executeQuery(strContent);
if(rs.next()) {
String newsText = rs.getString(2);
/* StringBuffer buf = new StringBuffer();
buf.append("<B>servlet</B>");
try {
resp.sendRedirect("RunApp");
catch(IOException e) {
e.printStackTrace();
// output.println(buf.toString());
// output.close();
my code for applet is
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.awt.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
public class EdApplet extends JApplet {
public void init() {
Container c;
c = getContentPane();
JPanel but = new JPanel();
c.add(but,BorderLayout.NORTH);
final JEditorPane je = new JEditorPane();
JScrollPane jsp = new JScrollPane(je);
HTMLEditorKit ht = new HTMLEditorKit();
je.setEditorKit(ht);
je.setEditable(true);
HTMLDocument mdoc = (HTMLDocument)ht.createDefaultDocument();
StyleSheet mcontext =mdoc.getStyleSheet();
je.setDocument(mdoc);
c.add(jsp,BorderLayout.CENTER);
JPanel bot = new JPanel();
c.add(bot,BorderLayout.SOUTH);
JButton save = new JButton("save");
but.add(save);
String str = getInitialText();
je.setText(str);
String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
try{
URL servletURL = new URL(servletUrl);
URLConnection servletConnection = servletURL.openConnection();
servletConnection.setRequestProperty("event","saveText");
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
catch(Exception e) {
// je.setText(e.printStackTrace());
ActionListener lst = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String save = je.getText();
saveText(save,je);
save.addActionListener(lst);
//je.setText("<B>this</B>");
//URLConnection servletConnection = null;
/* try {
String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
URL myUrl = new URL(servletUrl);
servletConnection = myUrl.openConnection();
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
/* BufferedReader br = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
String t = br.readLine();
je.setText(t);
catch(Exception e) {
e.printStackTrace();
/* ActionListener lst = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
BufferedReader br = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
String t = br.readLine();
je.setText(t);
click.addActionListener(lst);
/*void String changeText(UrlConnection con) {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream));
String t = br.readLine();
return t;
public String getInitialText()
//String me = null;
URLConnection textConnection = null;
StringBuffer sb = new StringBuffer();
try {
String textUrl="http://pc7:8100/mycontent.txt";
URL myUrl = new URL(textUrl);
textConnection = myUrl.openConnection();
textConnection.setDoInput(true);
textConnection.setUseCaches(false);
BufferedReader br = new BufferedReader(new InputStreamReader(textConnection.getInputStream()));
// me = (String)servletConnection.getContent();
String s = null;
while((s = br.readLine())!=null) {
sb.append(s);
catch(Exception e) {
e.printStackTrace();
return sb.toString();
public void saveText(String saveStr,JEditorPane je) {
//String saveStr = je.getText();
//String servletUrl="http://pc7:8100/servlet/newDatabaseServlet?event='saveText'&newsid='2'";
//String servletGet="http://pc7:8100/servlet/newDatabaseServlet";
String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
//String servletUrl = servletGet + "?"
// + URLEncoder.encode("event") + "="
// + URLEncoder.encode("saveText");
// je.setText(servletUrl);
try {
URL servletURL = new URL(servletUrl);
URLConnection servletConnection = servletURL.openConnection();
// servletConnection.setRequestProperty("event","saveText");
servletConnection.setRequestProperty(
"User-Agent","Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
//System.out.println("from applet");
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
//Propertiew prop = new Properties();
// prop.put("event","saveText");
PrintStream out = new PrintStream(servletConnection.getOutputStream());
out.println("event");
out.close();
catch(IOException e) {
je.setText(e.toString());
kindly tell me what is the error
what is the best method of doing this
thanking u in anticipation
megha soodomg O_o
We cannot debug your code, but:
Did you try the servlet directly from your browser? Does it work?
Best regards from Germany,
r.v. -
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" %>
Maybe you are looking for
-
How to export data from MS Project 2010 to MS Excel 2010 with formatting
I have created a Project 2010 export map to Excel 2010. It works fine. I have two questions that I cannot determine an answer. I'm not sure if its a project or excel setting. I have spend hours trying to make it work with little success. 1. When
-
Down loading ALV List to local file /print
hi , We have a program that displays data on an ALV list. Then, when you click on the 'Print' icon, or try to download to a local file, it gives a short dump with a message 'OBJECTS_NOT_CHARLIKE'. Any solutions on the same .... thanks
-
Configure to call a BI query from CRM
Hi, I created a BI query in the BI system and I want to get it called from CRM 2007 web UI. There is a RFC connection between CRM and BI. Can anybody can list out all settings/configuration required to set inorder to list this query in the Web UI. T
-
I am trying to add a number in Egypt and unable to. Why Egypt is not listed?
-
Good Friday to you all. I am struggling to figure out why my computer is running so painfully slow. All applications even safari. I have a word document open and safari running. I can hear the system running in the background all the time. Like i