javascript using jdbc
i know to validate aform , but i don't no how to connect javascript to a database, plz help me. i only know to use jdbc.but this is only a client project for me , not to go on using internet.plz help me with a database
nandini
May 30,
<%
try{
String name = request.getParameter("name");
String ps = request.getParameter("psw");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String url = "jdbc:odbc:login";
Connection con = null;
con= DriverManager.getConnection(url);
Statement st = con.createStatement();
//where name='"+nam+ "'";
//String sql= "SELECT * FROM login WHERE user = '"+name+ "'";
String sql = "SELECT * FROM login WHERE user='" + name + "'and psw='"+ps+"'";
//name='"+nam+ "',address='"+add+"',
ResultSet rs = st.executeQuery(sql);
rs.next();
String as = rs.getString(2);
String s = rs.getString(3);
//out.println(as);
//out.println(s);
if(name.equals(as) && ps.equals(s)){
response.sendRedirect("welcome.jsp");
}
else {
response.sendRedirect("Error.jsp");
}
}catch(Exception e){
out.println("Error"+e);
}
%>
athar (032424037@umt.edu.pk)
March 19,
Well nandini,
UR question seems 2 b unclear...
through javascript u cannot connect 2 database
but using the above code in java ....u can get
connected ....but u say u dont want 2 use internet
than u can try for stand alone app. But still without
internet an intranet application can be built using
web interface.
Rocky
March 22,
Javascript is client side. You simply cannot connect jdbc using javascript u need to have some serverside technology! .anything like java, php coldfusion or somethinglike that .
Vijyant
May 31,
hi ....
i ahve a project where i have to search for house ...
my website is in php and my database is in sql...and i have to use javascipt for search form can anybody help me and guide me how i can connect javascript with php and php to sql..
thanks
shehzad
October 14,
In PHP:
1) connect to the database, perform your query and store the search results in an array, e.g. $MyResults
2) write a loop-like-function, which puts your SQL results in a string, e.g. $gridData, formatted like this (example for an two-dimensional results array, containing ID's and names):
mydata_columns = [
"ID", "name"];
mydata_data = [
["1", "Pete"],
["2", "John"]
];
3. Define another string in PHP, e.g. $gridCode, containing the Javascript code to initialize the grid:
try {
var myGrid = new Active.Controls.Grid;
myGrid.name = 'myName';
myGrid.setRowCount(x);
myGrid.setColumnCount(y);
myGrid.setDataText(function(i, j){return mydata_data[i][j]});
myGrid.setColumnText(function(i){return mydata_columns[i]});
document.write(myGrid);
}
catch (error){
alert('Datagrid error: '+error.description);
}
4. Finally, echo both the string in your PHP file:
echo $gridData;
echo $gridCode;
5. Of course you should also add the links to the Grid Javascript and CSS files in the head of your document (adjust the path in href)
<link href="../../runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="../../runtime/lib/grid.js"></script>
Rekcor
October 16,