package mypack;
import java.sql.*;
public class jdbc
{
private static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //驱动
private static final String URL="jdbc:sqlserver://localhost:1433;DataBaseName=3070421088";
private static final String NAME = "sa"; //数据库登录账号
private static final String PASS="";//数据库登录密码
public static Connection getConn(){
Connection conn = null;
try {
Class.forName(DRIVER); //注册驱动
conn = DriverManager.getConnection(URL,NAME,PASS);//获取连接字符串
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage() +"注册驱动失败");
e.printStackTrace();
} catch(SQLException e){
System.out.println(e.getMessage() + "获取连接字符串错误");
e.printStackTrace();
}catch(Exception e){
System.out.println(e.getMessage() + "数据库连接错误");
}
return conn;
}
public static void main(String args[])
{
jdbc.getConn();
}
}
自己先放了点数据可以连接了,现在在弄怎么从TXT上传数据
import java.sql.*;
public class jdbc
{
private static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //驱动
private static final String URL="jdbc:sqlserver://localhost:1433;DataBaseName=3070421088";
private static final String NAME = "sa"; //数据库登录账号
private static final String PASS="";//数据库登录密码
public static Connection getConn(){
Connection conn = null;
try {
Class.forName(DRIVER); //注册驱动
conn = DriverManager.getConnection(URL,NAME,PASS);//获取连接字符串
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage() +"注册驱动失败");
e.printStackTrace();
} catch(SQLException e){
System.out.println(e.getMessage() + "获取连接字符串错误");
e.printStackTrace();
}catch(Exception e){
System.out.println(e.getMessage() + "数据库连接错误");
}
return conn;
}
public static void main(String args[])
{
jdbc.getConn();
}
}
[/code][code="java"]
自己先放了点数据可以连接了,现在在弄怎么从TXT上传数据