I need to connect MySQL datasource to a jsp page through eclipse. I need to add, delete and read data from tables. I am using Eclipse Helios, Tomcat Apache 7 and Struts 2. I found some related page How should I connect to JDBC database / datasource in a servlet based application? but i dont know how to use public Database().What do i import. Also pls tell me some simple procedure to add and access data from tables.
You need to learn JDBC first - http://download.oracle.com/javase/tutorial/jdbc/index.html - and then you need to add the appropriate Java MySQL driver to your application so that the JDBC connection creation string can locate it.
Start with the tutorial.
Edit: A very good JDBC-based database exploration program is the DBVisualizer - http://www.dbvis.com/ - where the free version can help you getting started as well as help you investigate database contents and an easy SQL editor for getting the selects right.
You have to download mysql server and MySqlWonkbench for better UI. https://dev.mysql.com/downloads/workbench/
You have to add mysql.jar file to run mysql on your eclipse.
https://dev.mysql.com/downloads/connector/j/5.1.html
Add jar file to your eclipse project
Rightclick on your project --> properties --> java Build path --> add external jar --> select your mysql jar from your pc.
refer this video
https://www.youtube.com/watch?v=5vzCjvUwMXg
refer this code for login/signup fusing jsp + mysql
https://github.com/Aksh0369/log_sin_jsp-MySql
Related
I have an Eclipse maven Web Dynamic Project using Postgres. After pulling from git, I got it locally.I installed Postgres on my Ubuntu 14.04 and with pgAdmin I manage to make everything work. Postgres is written on pom.xml as a dependency and I successfully manage to insert new data on my DB using my project. Although, I got this Eclipse error:
Problem with driver "IBM Data Server Driver for JDBC and SQLJ (JDBC 4.0) Default." (Error: Unable to locate JAR/zip in file system as specified by the driver definition: C.) IBM Data Server Driver for JDBC and SQLJ (JDBC 4.0) Default Driver Problems
Even with everything working, anyone knows how to remove this? Update project at Maven didn't work at all.
Ensure the the target .jar (like db2jcc.jar / db2jcc4.jar) file exists and is in your library path. When on the dialog for picking the driver .jar, simply click the find jar/zip button and find the file. Sometimes it is detected, but still does not work. If this happens, press the "clear all" button. Now repeat the above process. The .jar will be added and you will continue to driver connection and details dialog box.
How do I create data source in eclipse level in atg .?
I have removed jdbc folder from config and configured that jdbc folder in eclipse.
On build of Eclipse, that data source file needs to point the database and needs to start the server.
Like dynamo/ admin / or project need to up.
Can anyone help me with how to do these?
I want to use JPA to create an entity class that can be used with the persistence context to access my db2 nosql database. The problem is the #NoSql annotation is not being found.
As per http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/NoSQL/Configuring, I:
Created a web project
Enabled JPA via project properties-> Project Facets -> Check mark JPA v2.1
Under Project properties -> JPA -> Set Platform to EclipseLink 2.5x, Set JPA Implementation to Library Provided by Target Runtime
Setup server.xml with the datasource and the persistence.xml
I have java.persistence.org but not java.persistence.org.oracle.nosql. I'm not sure if I am suppose to download it or it should already be setup. And I also do not know how to use maven (and I would prefer not to).
Most tutorials online either only show HOW to use (and not configure) or use mysql connector and somewhere in the project config it just works. I greatly appreciate assistance!
I solved the problem by following this blog post: https://blogs.oracle.com/NoSQL/entry/eclipselink_jpa_and_oracle_nosql.
Excerpt:
Now at first glance it looks like EclipseLink 2.5 includes support for
NoSQL databases right out of the box, but in fact if you look closely
there is another specific NoSQL plugin download necessary. Download,
unzip and save this plugin in a directory e.g. /nosql-plugin . Later
you’ll need to get some libraries from it.
So go here to get the jar files and import the following into your project
org.eclipse.persistence.nosql_2.5.0*.jar
org.eclipse.persistence.oracle.nosql_2.5.0*.jar
javax.resource_1.5.0*.jar
To import go right-click project -> properties -> java build path -> Libraries tab -> Add External Jar -> Navigate to the jar files and import
Hullo - issue is this:
I wrote a servlet in Eclipse which requires mysql-connector-java-5.1.22-bin.jar
To compile I need to add the jar via the project's "Java Build Path"
To deploy I need to add the jar to the project's "Deployment Assembly"
To run the servlet within eclipse I need to add the jar to the servlet's Run Configuration -> Classpath
It's not the end of the world re-re-repeating myself like this, but it does seem odd.
Given that Eclipse gets a lot of other stuff correct I'm guessing / hoping that maybe I'm overlooking some feature to avoid this silliness (I cannot imagine a scenario where you'd benefit from entering this in 3 different spots ... but maybe I'm being uncreative here ...).
Insights appreciated :-)
The only thing you need to do is to drop the jar in WebContent/WEB-INF/lib.
You are developing a Java Web project, so the traditional place to put the required libs (JAR files etc) is under /WEB-INF/lib. And you do it only once.
In Eclipse, when you create Dynamic Web Project the appropriate project structure is generated for you (this is a development structure). In this case you place your JAR files in ProjectName/WebContent/WEB-INF/lib folder. And this folder is *automatically included in the project's build path.
Considering the fact that it is a Java Web project (you said you use servlets) you have to deploy your web app to some Application Server, like GlassFish, JBoss, WebLogic, WebSphere etc, or more simple Web Container like Apache Tomcat. If you do this thru Eclipse, then again your web project is automatically deployed.
NB!
There may be some additional details related to using libraries.
For instance, when it comes to using database drivers (MySql, PostgreSQL, Oracle etc) Tomcat advises the following while configuring JNDI Datasource (quote):
Before you proceed, don't forget to copy the JDBC Driver's jar into
$CATALINA_HOME/lib
In your case (MySQL) see the example here: MySQL DBCP Example
Also see my answer related to Webapp configuration file organization convention.
Hope this will help you.
P.S. Here is a step-by-step example: How do I access MySQL from a web application?
I am working with JSP and have a problem adding JDBC driver to my current project. I tried to build a path to jdbc library as well as copy and pasting JDBC jar directly into "lib" folder, but nothing works, i keep getting "No suitable driver found for jdbc:mysql://localhost:3306/mydb" error. Am i doing something wrong? is there other way to add jdbc?
Jar appears as follows in the picture:
Have you loaded the class correctly?
try this:
Class.forName("com.mysql.jdbc.Driver");
just before creating the connection.