File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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