老兄,""表示string结束,你要用\"转换
解决方案 »
- "1".substring(1).length()
- 没有main的HelloWord程序,求解释。
- JB找不到mail.jar?
- new 的作用?
- swing中的painting
- java怎么调用*.bat文件,请帮忙解决!!!!
- 在applet中如何放入一个jframe
- 为什么我的jb8总是保存不了jsp文件,以保存jsp文件的时候就出现com.borland.primetime.util.AssertionException:euc_cn
- tomcat的web-inf/classes下编译.java的问题,憋了很久了,希望好心人来看看!!100分相送!!
- 一个java初级问题
- 在html中 <input type="text" name="create_user" maxlength="12" size="12"> 不能限制中文字符个数???
- 请大家介绍一本Java入门的好书
String user,
String password)
throws SQLException
Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.Parameters:url - a database url of the form jdbc:subprotocol:subname
user - the database user on whose behalf the connection is being made
password - the user's passwordReturns:a connection to the URLThrows:SQLException - if a database access error occursconnectstring="jdbc:microsoft:sqlserver://192.168.0.21:1433","study","study";
only a String ,so it is wrong for that!
String user = "study";
String password = "study";
conn = DriverManager.getConnection(url, user, password);
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.21:1433","study","study"
);--------------------------->String a="jdbc:microsoft:sqlserver://192.168.0.21:1433";
Strign b="study";
String c="study";
conn=DriverManager.getConnection(a,b,c);
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection
("jdbc:microsoft:sqlserver://192.168.5.219:1433;DatabaseName=数据库名","用户名","密码");
其中有一项是连接串,但是我搞来搞去这个字符串不知道该写什么。
我写成
"jdbc:microsoft:sqlserver://192.168.0.21:1433","study","study"
连接数据库不行,写成
"jdbc:microsoft:sqlserver://192.168.0.21:1433,study,study"
也不行!
大家说到底如何处理
"jdbc:microsoft:sqlserver://192.168.0.21:1433,study,study"
然后用StringTokenizer 或者其它的把它分成三个String变量如
S1="jdbc:microsoft:sqlserver://192.168.0.21:1433";
s2="study";
s3="study";
后setup.
2.加入classpath中
______________________________________________________________________
<%@ page contentType = "text/html; charSet=gb2312" %>
<%@ page language="java" import = "java.sql.*" %>
<%
/**address: SQL Server的连接参数*/
String address = "jdbc:microsoft:sqlserver://127.0.0.1:1433";
/***user: 数据库用户名*/
String user="sa";
/**passwd: 用户密码*/
String passwd="";
/*数据库名*/
String database = "online"; DatabaseMetaData conMD = null;
java.sql.Statement stmt = null;
Connection con = null;
ResultSet sqlRst = null; try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(address,user,passwd); conMD = con.getMetaData();
con.setCatalog(database);
stmt = con.createStatement();
}catch(Exception fs) {
out.print("Connection ERROR</p> <br>");
}
out.print("Connection</p> <br>"); try
{
stmt=con.createStatement();
sqlRst = stmt.executeQuery("SELECT * FROM mytable");
out.print("stmt OK");
}catch(Exception gr)
{
out.print("stmt ERROR");
} while (sqlRst.next())
{
out.print("<p>name :" + sqlRst.getString("name") + "</p> <br>");
out.print("<p>old :" + sqlRst.getString("old") + "</p>");
}
%>