Este es mi clase, esta dentro de un package llamado clases
Código:
y este es el codigo para hacer la conexion.package clases; import java.sql.DriverManager; import java.sql.Connection; /** * * @author LHuacacolqui */ public class sqlserver { public static java.sql.Connection getSqlServerConnection(String database, String servername, int port, String username, String password) try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); String url="jdbc:microsoft:sqlserver://"+servername+":"+port+";DatabaseName="+database+";user="+username+";password="+password; Connection conn=DriverManager.getConnection(url); if(conn!=null) System.out.println("-->Connected to sql server:"+servername); else System.out.println("Unable to connect to sql server:"+servername); return conn; } catch(Exception e); { System.out.println("Error:"+e); return null; } }
Cita:
favor su ayuda, en la red no hay muchos tutoriales para hacer esto. <%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="clases.sqlserver" %>
<%@page import="java.sql.Connection"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Connection mic=sqlserver.getSqlServerConnection("Tenebrosa"," 127.0.0.1",1433,"sa","");
if(!mic.isClosed())
{
out.println("Conectado!");
}
%>
</body>
</html>
<%@page import="clases.sqlserver" %>
<%@page import="java.sql.Connection"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Connection mic=sqlserver.getSqlServerConnection("Tenebrosa"," 127.0.0.1",1433,"sa","");
if(!mic.isClosed())
{
out.println("Conectado!");
}
%>
</body>
</html>