my dog learned polymorphism*
The moose likes Servlets and the fly likes jdbc-jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "jdbc-jsp" Watch "jdbc-jsp" New topic


Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I want to connect my jsp prog with ms sql server.
If i want to pass the values which will be taken from jsp file & i want to put it in table,So what will be the command for that?
I want to pass the query as variable not the permanent values.
Plz help me out....
kichu kichu
Ranch Hand

Joined: May 10, 2001
Posts: 59
Hai kshitija,
This is the class file for connecting to the sql database--->
package packagename;
import java.sql.*;
public class getconnection
public Connection getconnection(String getdsnname)
String url="jdbcdbc:"+getdsnname;
Connection con=DriverManager.getConnection(url,"username","password");
return con;
catch(ClassNotFoundException e)
System.out.println("class not found....");
return null;
catch(SQLException se)
System.out.println("unable to connect");
return null;

*****************************************************************Here is a part of the jsp file which inserts data--->

Here assume that u have got two text boxes in whichu enter value.
U name them as txt1 and txt2.(I have not added the html code)
After putting in values in the textboxes ,u submit the values(say to the same jsp page).The values in the text boxes are obtained in the variables strProjName and strProjStat.
These values are then inserted into the database.

String conMfield=null;
Statement stmt=null;
ResultSet rs=null;
String sql="";
String strProjName;
String strProjStat;
getconnection gc=new getconnection();
Connection conMfield=gc.getconnection("DSN Name");
sql="insert into table(Field1,Field2)values('"+strProjName+"','"+strProjStat+"')";
catch(SQLException e)



I have given only a rough idea here for u.But hope this is of help to u.
If u have any problems,i will paste the entire code for you.
U can contact me at

[This message has been edited by kichu kichu (edited May 11, 2001).]
[This message has been edited by kichu kichu (edited May 11, 2001).]
[This message has been edited by kichu kichu (edited May 11, 2001).]
Consider Paul's rocket mass heater.
subject: jdbc-jsp
Similar Threads
passing values from ActionClass to jsp struts 1.1
After page loads, clear form bean value
passing values from jsp to bean
How to store the multiple check box values in the form bean
Passing Multiple Values to another jsp page from a List Box