This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "jdbc-jsp" Watch "jdbc-jsp" New topic
Author

jdbc-jsp

Anonymous
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....
kshitija
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)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
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;
try
{
getconnection gc=new getconnection();
Connection conMfield=gc.getconnection("DSN Name");
stmt=conMfield.createStatement();
sql="insert into table(Field1,Field2)values('"+strProjName+"','"+strProjStat+"')";
}
catch(SQLException e)
{
System.out.println("exception:"+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 kichuhere@rediffmail.com
regards,
kichu.

[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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc-jsp
 
Similar Threads
How to store the multiple check box values in the form bean
passing values from ActionClass to jsp struts 1.1
After page loads, clear form bean value
passing values from jsp to bean
Passing Multiple Values to another jsp page from a List Box