Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Retrieving Data from DataSource Configured in WebLogic 12.1

Suppose I have MySQL Database called RetailStore and have table Order containing order related data which customer submitted via online applications. Our requirement is to write java program which will read data from DataSource which is configured in Weblogic for our MYSQL Database.

You need to follow below steps.
  1. Create DataSource in WebLogic. I have used MySQL as DB and Weblogic 12.1.1 as Application Server.
  2. Test DataSource in weblogic
  3. Create HashMap consisting Initial Context Factory and Provider URL
  4. Create initial context Factory
  5. Do Lookup on context using JNDI configured for DataSource and have dataSource instance
  6. Get Connection from DataSource and Perform common JDBC Logic to read data from Table.

DataSource in WebLogic
Go to Services -> DataSource-> Create new DataSource. you will be asked to follow series of steps.
If you have MYSQL Db then please provide below configuration

MySQL Connection using Java

show databases; //display database name
create database database-name; //create database
use database-name; //use database
show tables from database-name; //show tables
show columns from table-name; //show colums
drop database database-name; //drop database

java syntax to connect to database

Connection con=DriverManager.getConnection("jdbc:mysql:///shop","root","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from item_master where category_name='"+cname+"' ");